/*
 *------------------------------------------------------------------------------
 * @File      :    tp9930_dvp.c
 * @Date      :    2021-3-20
 * @Author    :    lomboswer <lomboswer@lombotech.com>
 * @Brief     :    Source file for MDP(Media Development Platform).
 *
 * Copyright (C) 2020-2021, LomboTech Co.Ltd. All rights reserved.
 *------------------------------------------------------------------------------
 */
#include "ei_comm_camera.h"
#include "camera_usr.h"
#include <pthread.h>
#include <stdlib.h>

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */

#define SNS_ID 9930
#define SNS_NAME  "tp9930_dvp"
#define DEV_TYPE DVP

static SNS_STATE_S g_sastSns[VISS_MAX_DEV_NUM];

static EI_U8 u8Ch720pCount = 0;
static EI_U8 u8Ch1080pCount = 0;
static EI_U8 u8ChFormat[4] = {0xff};
static EI_U8 u8Count = 0;

enum{
    TYPE_720P60  = 0x00,
    TYPE_720P50  = 0x01,
    TYPE_1080P30 = 0x02,
    TYPE_1080P25 = 0x03,
    TYPE_720P30  = 0x04,
    TYPE_720P25  = 0x05,
    TYPE_SD,
    TYPE_OTHER,
};

enum{
    STD_TVI, //TVI
    STD_HDA, //AHD
};

typedef struct eiCAMERA_S {
    pthread_mutex_t mutex;
} CAMERA_S;

static const SNS_REG_S s_a1ch1080p25fpsBt1120[] = {
    {0x40, 0x04},
    {0x02, 0x44},
    {0x07, 0x80},
    {0x0b, 0xc0},
    {0x0c, 0x03},
    {0x0d, 0x73},
    {0x10, 0x00},
    {0x11, 0x40},
    {0x12, 0x40},
    {0x13, 0x00},
    {0x14, 0x00},
    {0x15, 0x01},
    {0x16, 0xf0},
    {0x17, 0x80},
    {0x18, 0x29},
    {0x19, 0x38},
    {0x1a, 0x47},
    {0x1c, 0x0a},
    {0x1d, 0x50},
    {0x20, 0x3c},
    {0x21, 0x46},
    {0x22, 0x36},
    {0x23, 0x3c},
    {0x24, 0x04},
    {0x25, 0xfe},
    {0x26, 0x0d},
    {0x27, 0x2d},
    {0x28, 0x00},
    {0x29, 0x48},
    {0x2a, 0x30},
    {0x2b, 0x60},
    {0x2c, 0x3a},
    {0x2d, 0x54},
    {0x2e, 0x40},
    {0x30, 0xa5},
    {0x31, 0x86},
    {0x32, 0xfb},
    {0x33, 0x60},
    {0x35, 0x05},
    {0x36, 0xca},
    {0x38, 0x00},
    {0x39, 0x1c},
    {0x3a, 0x32},
    {0x3b, 0x26},
    {0x4f, 0x03},
    {0x50, 0x00},
    {0x52, 0x00},
    {0xf1, 0x04},
    {0xf2, 0x77},
    {0xf3, 0x77},
    {0xf5, 0xF0},

    {0xf6, 0x44},//UYVY
    {0xf8, 0x00},//UYVY
    {0xfa, 0x03},
    {0xfb, 0x03},

    {0x4d, 0x07},//output enable
    {0x4e, 0x05},
};

static const SNS_REG_S s_a4ch1080p25fpsBt1120[] = {
     {0x40, 0x04},
     {0x3b, 0x20},
     {0x3d, 0xe0},
     {0x3d, 0x60},
     {0x3b, 0x25},
     {0x40, 0x40},
     {0x7a, 0x20},
     {0x3c, 0x20},
     {0x3c, 0x00},
     {0x7a, 0x25},
     {0x40, 0x00},
     {0x44, 0x57},
     {0x43, 0x12},
     {0x45, 0x09},
     {0xf4, 0xa0},
     {0x44, 0x07},
     /* video setting */
     {0x40, 0x04},
     {0x02, 0x44},
     {0x07, 0x80},
     {0x0b, 0xc0},
     {0x0c, 0x03},
     {0x0d, 0x73},
     {0x10, 0x00},
     {0x11, 0x40},
     {0x12, 0x40},
     {0x13, 0x00},
     {0x14, 0x00},
     {0x15, 0x01},
     {0x16, 0xf0},
     {0x17, 0x80},
     {0x18, 0x29},
     {0x19, 0x38},
     {0x1a, 0x47},
     {0x1c, 0x0a},
     {0x1d, 0x50},
     {0x20, 0x3c},
     {0x21, 0x46},
     {0x22, 0x36},
     {0x23, 0x3c},
     {0x24, 0x04},
     {0x25, 0xfe},
     {0x26, 0x0d},
     {0x27, 0x2d},
     {0x28, 0x00},
     {0x29, 0x48},
     {0x2a, 0x30},
     {0x2b, 0x60},
     {0x2c, 0x3a},
     {0x2d, 0x54},
     {0x2e, 0x40},
     {0x30, 0xa5},
     {0x31, 0x86},
     {0x32, 0xfb},
     {0x33, 0x60},
     {0x35, 0x05},
     {0x36, 0xca},
     {0x38, 0x00},
     {0x39, 0x1c},
     {0x3a, 0x32},
     {0x3b, 0x26},

     /* channel ID */
     {0x40, 0x00},
     {0x34, 0x10},
     {0x40, 0x01},
     {0x34, 0x11},
     {0x40, 0x02},
     {0x34, 0x12},
     {0x40, 0x03},
     {0x34, 0x13},
     /* output format */
     {0x4f, 0x03},
     {0x50, 0xb2},
     {0x52, 0xf6},
     {0xf1, 0x04},
     {0xf2, 0x77},
     {0xf3, 0x77},
     {0xf5, 0xF0},
     {0xf6, 0x10},
     {0xf8, 0x54},
     {0xfa, 0x88},
     {0xfb, 0x88},
     {0xf3, 0x71},
     /* output enable */
     {0x4d, 0x77},
     {0x4e, 0x75},
};

static const SNS_REG_S s_a4ch1080p30fpsBt1120[] = {
     {0x40, 0x04},
     {0x3b, 0x20},
     {0x3d, 0xe0},
     {0x3d, 0x60},
     {0x3b, 0x25},
     {0x40, 0x40},
     {0x7a, 0x20},
     {0x3c, 0x20},
     {0x3c, 0x00},
     {0x7a, 0x25},
     {0x40, 0x00},
     {0x44, 0x57},
     {0x43, 0x12},
     {0x45, 0x09},
     {0xf4, 0xa0},
     {0x44, 0x07},
     /* video setting */
     {0x40, 0x04},
     {0x02, 0x44},
     {0x07, 0x80},
     {0x0b, 0xc0},
     {0x0c, 0x03},
     {0x0d, 0x72},
     {0x10, 0x00},
     {0x11, 0x40},
     {0x12, 0x40},
     {0x13, 0x00},
     {0x14, 0x00},
     {0x15, 0x01},
     {0x16, 0xf0},
     {0x17, 0x80},
     {0x18, 0x29},
     {0x19, 0x38},
     {0x1a, 0x47},
     {0x1c, 0x08},
     {0x1d, 0x98},
     {0x20, 0x38},
     {0x21, 0x46},
     {0x22, 0x36},
     {0x23, 0x3c},
     {0x24, 0x04},
     {0x25, 0xfe},
     {0x26, 0x0d},
     {0x27, 0x2d},
     {0x28, 0x00},
     {0x29, 0x48},
     {0x2a, 0x30},
     /* { 0x2a, 0x3c }, */ /* blue screen */
     {0x2b, 0x60},
     {0x2c, 0x3a},
     {0x2d, 0x54},
     {0x2e, 0x40},
     {0x30, 0xa5},
     {0x31, 0x95},
     {0x32, 0xe0},
     {0x33, 0x60},
     {0x35, 0x05},
     {0x36, 0xca},
     {0x38, 0x00},
     {0x39, 0x1c},
     {0x3a, 0x32},
     {0x3b, 0x26},
     /* cha nnel ID */
     {0x40, 0x00},
     {0x34, 0x10},
     {0x40, 0x01},
     {0x34, 0x11},
     {0x40, 0x02},
     {0x34, 0x12},
     {0x40, 0x03},
     {0x34, 0x13},
     /* output format */
     {0x4f, 0x03},
     {0x50, 0xb2},
     {0x52, 0xf6},
     {0xf1, 0x04},
     {0xf2, 0x77},
     {0xf3, 0x77},
     {0xf5, 0xF0},
     {0xf6, 0x10},
     {0xf8, 0x54},
     {0xfa, 0x88},
     {0xfb, 0x88},
     /* output enable */
     {0x4d, 0x07},
     {0x4e, 0x05},

     {0xf3, 0x70},
     /* output enable */
     {0x4d, 0x77},
     {0x4e, 0x75},
};

/*4 channel 16bit bus-width bt1120 sdr*/
static const SNS_REG_S s_a4ch720p25fpsBt1120[] = {
    { 0x40, 0x04 },
    { 0x3b, 0x20 },
    { 0x3d, 0xe0 },
    { 0x3d, 0x60 },
    { 0x40, 0x40 },
    { 0x7a, 0x20 },
    { 0x3c, 0x20 },
    { 0x3c, 0x00 },
    { 0x7a, 0x25 },
    { 0x40, 0x00 },
    { 0x44, 0x17 },
    { 0x43, 0x12 },
    { 0x45, 0x09 },
    /* video setting */
    { 0x40, 0x04 },
    { 0x02, 0x4e },
    { 0x05, 0x00 },
    { 0x06, 0x32 },
    { 0x07, 0xc0 },
    { 0x08, 0x00 },
    { 0x09, 0x24 },
    { 0x0a, 0x48 },
    { 0x0b, 0xc0 },
    { 0x0c, 0x13 },
    { 0x0d, 0x71 },
    { 0x0e, 0x00 },
    { 0x0f, 0x00 },
    { 0x10, 0x00 },
    { 0x11, 0x40 },
    { 0x12, 0x40 },
    { 0x13, 0x00 },
    { 0x14, 0x00 },
    { 0x15, 0x13 },
    { 0x16, 0x19 },
    { 0x17, 0x00 },
    { 0x18, 0x19 },
    { 0x19, 0xd0 },
    { 0x1a, 0x25 },
    { 0x1b, 0x00 },
    { 0x1c, 0x07 },
    { 0x1d, 0xbc },
    { 0x1e, 0x60 },
    { 0x1f, 0x06 },
    { 0x20, 0x40 },
    { 0x21, 0x46 },
    { 0x22, 0x36 },
    { 0x23, 0x3c },
    { 0x24, 0x04 },
    { 0x25, 0xfe },
    { 0x26, 0x01 },
    { 0x27, 0x2d },
    { 0x28, 0x00 },
    { 0x29, 0x48 },
    { 0x2a, 0x34 },
    { 0x2b, 0x60 },
    { 0x2c, 0x3a },
    { 0x2d, 0x5a },
    { 0x2e, 0x40 },
    { 0x2f, 0x06 },
    { 0x30, 0x9e },
    { 0x31, 0x20 },
    { 0x32, 0x01 },
    { 0x33, 0x90 },
    { 0x35, 0x25 },
    { 0x36, 0xca },
    { 0x37, 0x00 },
    { 0x38, 0x00 },
    { 0x39, 0x18 },
    { 0x3a, 0x32 },
    { 0x3b, 0x26 },
    { 0x3c, 0x00 },
    { 0x3d, 0x60 },
    { 0x3e, 0x00 },
    { 0x3f, 0x00 },
    /* channel ID */
    { 0x40, 0x00 },
    { 0x34, 0x10 },
    { 0x40, 0x01 },
    { 0x34, 0x11 },
    { 0x40, 0x02 },
    { 0x34, 0x12 },
    { 0x40, 0x03 },
    { 0x34, 0x13 },
    /* output format */
    { 0x4f, 0x03 },
    { 0x50, 0xA3 },
    { 0x52, 0xE7 },
    { 0xf1, 0x04 },
    { 0xf2, 0x77 },
    { 0xf3, 0x0c },
    { 0xf4, 0x00 },
    { 0xf5, 0xff },
    { 0xf6, 0x10 },
    { 0xf8, 0x54 },
    { 0xfa, 0x88 },
    { 0xfb, 0x88 },
    { 0xf4, 0x80 },
    /* output enable */
    { 0x4d, 0x07 },
    { 0x4e, 0x05 },
};

/*4 channel 16bit bus-width bt1120 sdr*/
static const SNS_REG_S s_a4ch720p30fpsBt1120[] = {
    { 0x40, 0x04 },
    { 0x3b, 0x20 },
    { 0x3d, 0xe0 },
    { 0x3d, 0x60 },
    { 0x40, 0x40 },
    { 0x7a, 0x20 },
    { 0x3c, 0x20 },
    { 0x3c, 0x00 },
    { 0x7a, 0x25 },
    { 0x40, 0x00 },
    { 0x44, 0x17 },
    { 0x43, 0x12 },
    { 0x45, 0x09 },
    /* video setting */
    { 0x40, 0x04 },
    { 0x02, 0x4e },
    { 0x05, 0x00 },
    { 0x06, 0x32 },
    { 0x07, 0xc0 },
    { 0x08, 0x00 },
    { 0x09, 0x24 },
    { 0x0a, 0x48 },
    { 0x0b, 0xc0 },
    { 0x0c, 0x13 },
    { 0x0d, 0x70 },
    { 0x0e, 0x00 },
    { 0x0f, 0x00 },
    { 0x10, 0x00 },
    { 0x11, 0x40 },
    { 0x12, 0x40 },
    { 0x13, 0x00 },
    { 0x14, 0x00 },
    { 0x15, 0x13 },
    { 0x16, 0x19 },
    { 0x17, 0x00 },
    { 0x18, 0x19 },
    { 0x19, 0xd0 },
    { 0x1a, 0x25 },
    { 0x1b, 0x00 },
    { 0x1c, 0x06 },
    { 0x1d, 0x72 },
    { 0x1e, 0x60 },
    { 0x1f, 0x06 },
    { 0x20, 0x40 },
    { 0x21, 0x46 },
    { 0x22, 0x36 },
    { 0x23, 0x3c },
    { 0x24, 0x04 },
    { 0x25, 0xfe },
    { 0x26, 0x01 },
    { 0x27, 0x2d },
    { 0x28, 0x00 },
    { 0x29, 0x48 },
    { 0x2a, 0x34 },
    { 0x2b, 0x60 },
    { 0x2c, 0x3a },
    { 0x2d, 0x5a },
    { 0x2e, 0x40 },
    { 0x2f, 0x06 },
    { 0x30, 0x9d },
    { 0x31, 0xca },
    { 0x32, 0x01 },
    { 0x33, 0xd0 },
    { 0x35, 0x25 },
    { 0x36, 0xca },
    { 0x37, 0x00 },
    { 0x38, 0x00 },
    { 0x39, 0x18 },
    { 0x3a, 0x32 },
    { 0x3b, 0x26 },
    { 0x3c, 0x00 },
    { 0x3d, 0x60 },
    { 0x3e, 0x00 },
    { 0x3f, 0x00 },
    /* channel ID */
    { 0x40, 0x00 },
    { 0x34, 0x10 },
    { 0x40, 0x01 },
    { 0x34, 0x11 },
    { 0x40, 0x02 },
    { 0x34, 0x12 },
    { 0x40, 0x03 },
    { 0x34, 0x13 },
    /* output format */
    { 0x4f, 0x03 },
    { 0x50, 0xA3 },
    { 0x52, 0xE7 },
    { 0xf1, 0x04 },
    { 0xf2, 0x77 },
    { 0xf3, 0x0c },
    { 0xf4, 0x00 },
    { 0xf5, 0xff },
    { 0xf6, 0x10 },
    { 0xf8, 0x54 },
    { 0xfa, 0x88 },
    { 0xfb, 0x88 },
    { 0xf4, 0x80 },
    /* output enable */
    { 0x4d, 0x07 },
    { 0x4e, 0x05 },
};

/*2 channel 16bit bus-width bt1120 ddr*/
static const SNS_REG_S s_a2ch1080p50fpsBt1120_tvi[] = {
    { 0x40, 0x04 },
    { 0x3b, 0x20 },
    { 0x3d, 0xe0 },
    { 0x3d, 0x60 },
    { 0x3b, 0x25 },
    { 0x40, 0x40 },
    { 0x7a, 0x20 },
    { 0x3c, 0x20 },
    { 0x3c, 0x00 },
    { 0x7a, 0x25 },
    { 0x40, 0x00 },
    { 0x44, 0x07 },
    { 0x43, 0x12 },
    { 0x45, 0x09 },
    /* video setting */
    { 0x40, 0x04 },
    { 0x02, 0x48 },
    { 0x05, 0x00 },
    { 0x06, 0x32 },
    { 0x07, 0x80 },
    { 0x08, 0x00 },
    { 0x09, 0x24 },
    { 0x0a, 0x48 },
    { 0x0b, 0xc0 },
    { 0x0c, 0x03 },
    { 0x0d, 0x50 },
    { 0x0e, 0x00 },
    { 0x0f, 0x00 },
    { 0x10, 0x00 },
    { 0x11, 0x40 },
    { 0x12, 0x40 },
    { 0x13, 0x00 },
    { 0x14, 0x00 },
    { 0x15, 0x03 },
    { 0x16, 0xf0 },
    { 0x17, 0x80 },
    { 0x18, 0x12 },
    { 0x19, 0x38 },
    { 0x1a, 0x47 },
    { 0x1c, 0x0a },
    { 0x1d, 0x4e },
    { 0x20, 0x50 },
    { 0x21, 0x84 },
    { 0x22, 0x36 },
    { 0x23, 0x3c },
    { 0x24, 0x04 },
    { 0x25, 0xff },
    { 0x26, 0x05 },
    { 0x27, 0xad },
    { 0x28, 0x00 },
    { 0x29, 0x48 },
    { 0x2a, 0x30 },
    //{ 0x2a, 0x3c },
    { 0x2b, 0x60 },
    { 0x2c, 0x1a },
    { 0x2d, 0x40 },
    { 0x2e, 0x70 },
    { 0x30, 0x74 },
    { 0x31, 0x9b },
    { 0x32, 0xa5 },
    { 0x33, 0xe0 },
    { 0x35, 0x05 },
    { 0x38, 0x40 },
    { 0x39, 0x48 },
    { 0x3a, 0x12 },
    { 0x3b, 0x25 },
    { 0x3d, 0x60 },
    { 0x3e, 0x00 },
    { 0x3f, 0x00 },
    /* channel ID */
    { 0x40, 0x00 },
    { 0x34, 0x10 },
    { 0x40, 0x01 },
    { 0x34, 0x11 },
    { 0x40, 0x02 },
    { 0x34, 0x12 },
    { 0x40, 0x03 },
    { 0x34, 0x13 },
    /* output format */
    { 0x4f, 0x03 },
    { 0x50, 0x00 },
    { 0x52, 0x00 },
    { 0xf1, 0x04 },
    { 0xf2, 0x77 },
    { 0xf3, 0x77 },// for evb
    //{ 0xf3, 0x71 },// for other
    { 0xf4, 0xa0 },
    { 0xf5, 0xf0 },
    { 0xf6, 0x10 },
    { 0xf8, 0x54 },
    { 0xfa, 0x88 },
    { 0xfb, 0x88 },
    /* output enable */
    { 0x4d, 0x07 },
    { 0x4e, 0x05 },
};

static const SNS_REG_S s_a4ch720p30fpsBt656[] = {
    //PLL reset 
    {0x40, 0x04},
    {0x3b, 0x20},
    {0x3d, 0xe0},
    {0x3d, 0x60},
    {0x3b, 0x25},
    {0x40, 0x40},
    {0x7a, 0x20},
    {0x3c, 0x20},
    {0x3c, 0x00},
    {0x7a, 0x25},
    {0x40, 0x00},
    {0x44, 0x07},
    {0x43, 0x12},
    {0x45, 0x09},
    //video setting
    {0x40, 0x04},
    {0x02, 0xce},
    {0x05, 0x00},
    {0x06, 0x32},
    {0x07, 0xc0},
    {0x08, 0x00},
    {0x09, 0x24},
    {0x0a, 0x48},
    {0x0b, 0xc0},
    {0x0c, 0x13},
    {0x0d, 0x70},
    {0x0e, 0x00},
    {0x0f, 0x00},
    {0x10, 0x00},
    {0x11, 0x40},
    {0x12, 0x40},
    {0x13, 0x00},
    {0x14, 0x00},
    {0x15, 0x13},
    {0x16, 0x16},
    {0x17, 0x00},
    {0x18, 0x1b},
    {0x19, 0xd0},
    {0x1a, 0x25},
    {0x1b, 0x00},
    {0x1c, 0x06},
    {0x1d, 0x72},
    {0x1e, 0x60},
    {0x1f, 0x06},
    {0x20, 0x40},
    {0x21, 0x46},
    {0x22, 0x36},
    {0x23, 0x3c},
    {0x24, 0x04},
    {0x25, 0xfe},
    {0x26, 0x01},
    {0x27, 0x2d},
    {0x28, 0x00},
    {0x29, 0x48},
    {0x2a, 0x30},
    {0x2b, 0x60},
    {0x2c, 0x3a},
    {0x2d, 0x5a},
    {0x2e, 0x40},
    {0x2f, 0x06},
    {0x30, 0x9d},
    {0x31, 0xca},
    {0x32, 0x01},
    {0x33, 0xd0},
    {0x35, 0x25},
    {0x36, 0xca},
    {0x37, 0x00},
    {0x38, 0x00},
    {0x39, 0x18},
    {0x3a, 0x32},
    {0x3b, 0x26},
    {0x3c, 0x00},
    {0x3d, 0x60},
    {0x3e, 0x00},
    {0x3f, 0x00},
    //channel ID
    {0x40, 0x00},
    {0x34, 0x10},
    {0x40, 0x01},
    {0x34, 0x11},
    {0x40, 0x02},
    {0x34, 0x12},
    {0x40, 0x03},
    {0x34, 0x13},
    //output format
    {0x4f, 0x03},
    {0x50, 0xa3},
    {0x52, 0xa3},
    {0xf1, 0x04},
    {0xf2, 0x77},
    {0xf3, 0x77},
    {0xf4, 0x20},
    {0xf5, 0xff},
    {0xf6, 0x10},
    {0xf8, 0x10},
    {0xfa, 0x88},
    {0xfb, 0x88},
    //output enable
    {0x4d, 0x07},
    {0x4e, 0x05},

};

static const SNS_REG_S s_a4ch720p25fpsBt656[] = {
    //PLL reset
    {0x40, 0x04},
    {0x3b, 0x20},
    {0x3d, 0xe0},
    {0x3d, 0x60},
    {0x3b, 0x25},
    {0x40, 0x40},
    {0x7a, 0x20},
    {0x3c, 0x20},
    {0x3c, 0x00},
    {0x7a, 0x25},
    {0x40, 0x00},
    {0x44, 0x07},
    {0x43, 0x12},
    {0x45, 0x09},
    //video setting
    {0x40, 0x04},
    {0x02, 0xce},
    {0x05, 0x00},
    {0x06, 0x32},
    {0x07, 0xc0},
    {0x08, 0x00},
    {0x09, 0x24},
    {0x0a, 0x48},
    {0x0b, 0xc0},
    {0x0c, 0x13},
    {0x0d, 0x71},
    {0x0e, 0x00},
    {0x0f, 0x00},
    {0x10, 0x00},
    {0x11, 0x40},
    {0x12, 0x40},
    {0x13, 0x00},
    {0x14, 0x00},
    {0x15, 0x13},
    {0x16, 0x16},
    {0x17, 0x00},
    {0x18, 0x1b},
    {0x19, 0xd0},
    {0x1a, 0x25},
    {0x1b, 0x00},
    {0x1c, 0x07},
    {0x1d, 0xbc},
    {0x1e, 0x60},
    {0x1f, 0x06},
    {0x20, 0x40},
    {0x21, 0x46},
    {0x22, 0x36},
    {0x23, 0x3c},
    {0x24, 0x04},
    {0x25, 0xfe},
    {0x26, 0x01},
    {0x27, 0x2d},
    {0x28, 0x00},
    {0x29, 0x48},
    {0x2a, 0x30},
    //{0x2a, 0x3c}, /* blue screen */
    {0x2b, 0x60},
    {0x2c, 0x3a},
    {0x2d, 0x5a},
    {0x2e, 0x40},
    {0x2f, 0x06},
    {0x30, 0x9e},
    {0x31, 0x20},
    {0x32, 0x01},
    {0x33, 0x90},
    {0x35, 0x25},
    {0x36, 0xca},
    {0x37, 0x00},
    {0x38, 0x00},
    {0x39, 0x18},
    {0x3a, 0x32},
    {0x3b, 0x26},
    {0x3c, 0x00},
    {0x3d, 0x60},
    {0x3e, 0x00},
    {0x3f, 0x00},
    //channel ID
    {0x40, 0x00},
    {0x34, 0x10},
    {0x40, 0x01},
    {0x34, 0x11},
    {0x40, 0x02},
    {0x34, 0x12},
    {0x40, 0x03},
    {0x34, 0x13},
    //output format
    {0x4f, 0x03},
    {0x50, 0xa3},
    {0x52, 0xa3},
    {0xf1, 0x04},
    {0xf2, 0x77},
    {0xf3, 0x77},
    {0xf4, 0x20},
    {0xf5, 0xff},
    {0xf6, 0x10},
    {0xf8, 0x10},
    {0xfa, 0x88},
    {0xfb, 0x88},
    //output enable
    {0x4d, 0x07},
    {0x4e, 0x05},
};

static const SNS_REG_S s_a2ch1080p30fpsBt656[] = {
    //PLL reset
    {0x40, 0x04},
    {0x3b, 0x20},
    {0x3d, 0xe0},
    {0x3d, 0x60},
    {0x3b, 0x25},
    {0x40, 0x40},
    {0x7a, 0x20},
    {0x3c, 0x20},
    {0x3c, 0x00},
    {0x7a, 0x25},
    {0x40, 0x00},
    {0x44, 0x07},
    {0x43, 0x12},
    {0x45, 0x09},
    {0xf4, 0xa0},
    //video setting
    {0x40, 0x04},
    {0x02, 0xcc},
    {0x05, 0x00},
    {0x06, 0x32},
    {0x07, 0x80},
    {0x08, 0x00},
    {0x09, 0x24},
    {0x0a, 0x48},
    {0x0b, 0xc0},
    {0x0c, 0x03},
    {0x0d, 0x72},
    {0x0e, 0x00},
    {0x0f, 0x00},
    {0x10, 0x00},
    {0x11, 0x40},
    {0x12, 0x40},
    {0x13, 0x00},
    {0x14, 0x00},
    {0x15, 0x01},
    {0x16, 0xf0},
    {0x17, 0x80},
    {0x18, 0x2a},
    {0x19, 0x38},
    {0x1a, 0x47},
    {0x1c, 0x08},
    {0x1d, 0x98},
    {0x20, 0x38},
    {0x21, 0x46},
    {0x22, 0x36},
    {0x23, 0x3c},
    {0x24, 0x04},
    {0x25, 0xfe},
    {0x26, 0x0d},
    {0x27, 0x2d},
    {0x28, 0x00},
    {0x29, 0x48},
    {0x2a, 0x30},
    {0x2b, 0x60},
    {0x2c, 0x3a},
    {0x2d, 0x54},
    {0x2e, 0x40},
    {0x30, 0xa5},
    {0x31, 0x95},
    {0x32, 0xe0},
    {0x33, 0x60},
    {0x35, 0x05},
    {0x36, 0xca},
    {0x38, 0x00},
    {0x39, 0x1c},
    {0x3a, 0x32},
    {0x3b, 0x26},
    {0x3c, 0x00},
    {0x3d, 0x60},
    {0x3e, 0x00},
    {0x3f, 0x00},
    //channel ID
    {0x40, 0x00},
    {0x34, 0x10},
    {0x40, 0x01},
    {0x34, 0x11},
    {0x40, 0x02},
    {0x34, 0x10},
    {0x40, 0x03},
    {0x34, 0x11},
    //output format
    {0x4f, 0x03},
    {0x50, 0x00},
    {0x52, 0x00},
    {0xf1, 0x04},
    {0xf2, 0x77},
    {0xf3, 0x77},
    {0xf5, 0xf0},
    {0xf6, 0x10},
    {0xf8, 0x23},
    {0xfa, 0x88},
    {0xfb, 0x88},
    //output enable
    {0x4d, 0x07},
    {0x4e, 0x05},

};

static const SNS_REG_S s_a2ch1080p25fpsBt656[] = {
    //PLL Reset
    {0x40, 0x04},
    {0x3b, 0x20},
    {0x3d, 0xe0},
    {0x3d, 0x60},
    {0x3b, 0x25},
    {0x40, 0x40},
    {0x7a, 0x20},
    {0x3c, 0x20},
    {0x3c, 0x00},
    {0x7a, 0x25},
    {0x40, 0x00},
    {0x44, 0x07},
    {0x43, 0x12},
    {0x45, 0x09},
    {0xf4, 0xa0}, 
    //video setting
    {0x40, 0x04},
    {0x02, 0xcc},
    {0x05, 0x00},
    {0x06, 0x32},
    {0x07, 0x80},
    {0x08, 0x00},
    {0x09, 0x24},
    {0x0a, 0x48},
    {0x0b, 0xc0},
    {0x0c, 0x03},
    {0x0d, 0x73},
    {0x10, 0x00},
    {0x11, 0x40},
    {0x12, 0x40},
    {0x13, 0x00},
    {0x14, 0x00},
    {0x15, 0x01},
    {0x16, 0xf0},
    {0x17, 0x80},
    {0x18, 0x2a},
    {0x19, 0x38},
    {0x1a, 0x47},
    {0x1c, 0x0a},
    {0x1d, 0x50},
    {0x20, 0x3c},
    {0x21, 0x46},
    {0x22, 0x36},
    {0x23, 0x3c},
    {0x24, 0x04},
    {0x25, 0xfe},
    {0x26, 0x0d},
    {0x27, 0x2d},
    {0x28, 0x00},
    {0x29, 0x48},
    {0x2a, 0x30},
    {0x2b, 0x60},
    {0x2c, 0x3a},
    {0x2d, 0x54},
    {0x2e, 0x40},
    {0x30, 0xa5},
    {0x31, 0x86},
    {0x32, 0xfb},
    {0x33, 0x60},
    {0x35, 0x05},
    {0x36, 0xca},
    {0x38, 0x00},
    {0x39, 0x1c},
    {0x3a, 0x32},
    {0x3b, 0x26},
    //channel ID
    {0x40, 0x00},
    {0x34, 0x10},
    {0x40, 0x01},
    {0x34, 0x11},
    {0x40, 0x02},
    {0x34, 0x10},
    {0x40, 0x03},
    {0x34, 0x11},
    //output format
    {0x4f, 0x03},
    {0x50, 0x00},
    {0x52, 0x00},
    {0xf1, 0x04},
    {0xf2, 0x77},
    {0xf3, 0x77},
    {0xf5, 0xf0},
    {0xf6, 0x01},
    {0xf8, 0x23},
    {0xfa, 0x88},
    {0xfb, 0x88},
    //output enable
    {0x4d, 0x07},
    {0x4e, 0x05},
};

static const SNS_REG_S Audio_pcm_8k_16bit_8chns[] = {
    /* enable audio */
    { 0x40, 0x40},
    { 0x00, 0x01}, /* AIN1 ~ 4, for POS0,2,4, 6  */
    { 0x02, 0x02},
    { 0x04, 0x03},
    { 0x06, 0x04},
    { 0x08, 0x05}, /* AIN1 ~ 4, for POS8,A,C, E  */
    { 0x0A, 0x06},
    { 0x0C, 0x07},
    { 0x0E, 0x08},
    { 0x17, 0x80}, /* record 16bit i2s mode */
    { 0x1b, 0x01}, /* playback 16bit i2s */
    { 0x18, 0xE0},
    { 0x19, 0x1F},
    { 0x1a, 0x15}, /* first chip digital input */
    { 0x37, 0x20},
    { 0x38, 0x38},
    { 0x3E, 0x00},
    { 0x7a, 0x25},
    { 0x3d, 0x01}, /* reset */
};

static CAMERA_POWER_ACT_S s_stPowerUpAct[] = {
    {SNS_RESET, SNS_DOWN},
    {SNS_DELAY, 100},
    {SNS_RESET,  SNS_UP},
    {SNS_DELAY, 100},
};

static CAMERA_POWER_ACT_S s_sPowerDownAct[] = {
    {SNS_RESET, SNS_DOWN},
    {SNS_DELAY, 10},
};

static SNS_TYPE_ATTR_S s_astSnsAttr[] = {
    {
        .enSnsType                  = TP9930_DVP_ADAPTIVE_MASHUP_BT656_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .enRgbSeq                   = VISS_YUV_SEQ_C0C1C2C3,
        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT656,
        .stDevCfg.stVicCfg.enPclkSm = VISS_DDR,
        .enWorkMode                 = VISS_WORK_MODE_4Chn,
        .u32ModuleClk               = 148500000,

        .u32Mclock                  = 27000000,
        .u32FrameRate               = 30,

        .stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0,

    },
    {
        .enSnsType                  = TP9930_DVP_1920_1080_25FPS_1CH_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .stSize                     = {1920, 1080},
        .u32Mclock                  = 27000000,
        .u32FrameRate               = 25,
        .astRegCfgs[0].pstRegs      = s_a1ch1080p25fpsBt1120,
        .astRegCfgs[0].u32RegsCnt   = ARRAY_SIZE(s_a1ch1080p25fpsBt1120),

        .enYuvSeq                   = VISS_YUV_SEQ_C0C1C2C3,
        .enWorkMode                 = VISS_WORK_MODE_1Chn,

        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT1120_M0,
    },
    {
        .enSnsType                  = TP9930_DVP_1920_1080_25FPS_4CH_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .stSize                     = {1920, 1080},
        .u32ModuleClk               = 198000000,
        .u32Mclock                  = 27000000,
        .u32FrameRate               = 25,
        .astRegCfgs[0].pstRegs      = s_a4ch1080p25fpsBt1120,
        .astRegCfgs[0].u32RegsCnt   = ARRAY_SIZE(s_a4ch1080p25fpsBt1120),
        .enYuvSeq                   = VISS_YUV_SEQ_C1C0C3C2,
        .enWorkMode                 = VISS_WORK_MODE_4Chn,

        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT1120_M0,
        .stDevCfg.stVicCfg.enPclkSm = VISS_DDR,
        .stDevCfg.stVicCfg.u32IoInv = PCLK_INV,
        .stDevCfg.stVicCfg.eYcSync  = VISS_H8,
    },
    {
        .enSnsType                  = TP9930_DVP_1920_1080_30FPS_4CH_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .stSize                     = {1920, 1080},
        .u32ModuleClk               = 198000000,
        .u32Mclock                  = 27000000,
        .u32FrameRate               = 30,
        .astRegCfgs[0].pstRegs      = s_a4ch1080p30fpsBt1120,
        .astRegCfgs[0].u32RegsCnt   = ARRAY_SIZE(s_a4ch1080p30fpsBt1120),
        .enYuvSeq                   = VISS_YUV_SEQ_C1C0C3C2,
        .enWorkMode                 = VISS_WORK_MODE_4Chn,

        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT1120_M0,
        .stDevCfg.stVicCfg.enPclkSm = VISS_DDR,
        .stDevCfg.stVicCfg.u32IoInv = PCLK_INV,
        .stDevCfg.stVicCfg.eYcSync  = VISS_H8,
    },
    {
        .enSnsType                  = TP9930_DVP_1920_1080_XXFPS_4CH_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .stSize                     = {1920, 1080},
        .u32ModuleClk               = 198000000,
        .u32Mclock                  = 27000000,
        .enYuvSeq                   = VISS_YUV_SEQ_C1C0C3C2,
        .enWorkMode                 = VISS_WORK_MODE_4Chn,

        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT1120_M0,
        .stDevCfg.stVicCfg.enPclkSm = VISS_DDR,
        .stDevCfg.stVicCfg.u32IoInv = PCLK_INV,
        .stDevCfg.stVicCfg.eYcSync  = VISS_H8,
    },
    {
        .enSnsType                  = TP9930_DVP_1280_720_25FPS_4CH_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .stSize                     = {1280, 720},
        .u32ModuleClk               = 148500000,
        .u32Mclock                  = 27000000,
        .u32FrameRate               = 25,
        .astRegCfgs[0].pstRegs      = s_a4ch720p25fpsBt1120,
        .astRegCfgs[0].u32RegsCnt   = ARRAY_SIZE(s_a4ch720p25fpsBt1120),
        .enYuvSeq                   = VISS_YUV_SEQ_C1C0C3C2,
        .enWorkMode                 = VISS_WORK_MODE_4Chn,

        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT1120_M0,
        .stDevCfg.stVicCfg.enPclkSm = VISS_SDR,
        .stDevCfg.stVicCfg.u32IoInv = PCLK_INV,
        .stDevCfg.stVicCfg.eYcSync  = VISS_H8,
    },
    {
        .enSnsType                  = TP9930_DVP_1280_720_30FPS_4CH_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .stSize                     = {1280, 720},
        .u32ModuleClk               = 148500000,
        .u32Mclock                  = 27000000,
        .u32FrameRate               = 30,
        .astRegCfgs[0].pstRegs      = s_a4ch720p30fpsBt1120,
        .astRegCfgs[0].u32RegsCnt   = ARRAY_SIZE(s_a4ch720p30fpsBt1120),
        .enYuvSeq                   = VISS_YUV_SEQ_C1C0C3C2,
        .enWorkMode                 = VISS_WORK_MODE_4Chn,

        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT1120_M0,
        .stDevCfg.stVicCfg.enPclkSm      = VISS_SDR,
        .stDevCfg.stVicCfg.u32IoInv = PCLK_INV,
        .stDevCfg.stVicCfg.eYcSync  = VISS_H8,
    },
    {
        .enSnsType                  = TP9930_DVP_TVI_1920_1080_50FPS_2CH_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .stSize                     = {1920, 1080},
        .u32ModuleClk               = 198000000,
        .u32Mclock                  = 27000000,
        .u32FrameRate               = 50,
        .astRegCfgs[0].pstRegs      = s_a2ch1080p50fpsBt1120_tvi,
        .astRegCfgs[0].u32RegsCnt   = ARRAY_SIZE(s_a2ch1080p50fpsBt1120_tvi),
        .enYuvSeq                   = VISS_YUV_SEQ_C1C0C3C2,
        .enWorkMode                 = VISS_WORK_MODE_2Chn,

        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT1120_M0,
        .stDevCfg.stVicCfg.enPclkSm = VISS_DDR,
        .stDevCfg.stVicCfg.u32IoInv = PCLK_INV,
        .stDevCfg.stVicCfg.eYcSync  = VISS_H8,
        .stDevCfg.stVicCfg.u32PclkPhase = 10,
    },
    {
        .enSnsType                  = TP9930_DVP_1280_720_30FPS_4CH_BT656_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .stSize                     = {1280, 720},
        .u32ModuleClk               = 148500000,
        .u32Mclock                  = 27000000,
        .u32FrameRate               = 30,
        .astRegCfgs[0].pstRegs      = s_a4ch720p30fpsBt656,
        .astRegCfgs[0].u32RegsCnt   = ARRAY_SIZE(s_a4ch720p30fpsBt656),
        .enYuvSeq                   = VISS_YUV_SEQ_C0C1C2C3,
        .enWorkMode                 = VISS_WORK_MODE_4Chn,

        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT656,
        .stDevCfg.stVicCfg.enPclkSm = VISS_DDR,
        .stDevCfg.stVicCfg.u32IoInv = PCLK_INV,
        .stDevCfg.stVicCfg.eYcSync  = VISS_L8,

        .stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0,
    },
    {
        .enSnsType                  = TP9930_DVP_1280_720_25FPS_4CH_BT656_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .stSize                     = {1280, 720},
        .u32ModuleClk               = 148500000,
        .u32Mclock                  = 27000000,
        .u32FrameRate               = 25,
        .astRegCfgs[0].pstRegs      = s_a4ch720p25fpsBt656,
        .astRegCfgs[0].u32RegsCnt   = ARRAY_SIZE(s_a4ch720p25fpsBt656),
        .enYuvSeq                   = VISS_YUV_SEQ_C0C1C2C3,
        .enWorkMode                 = VISS_WORK_MODE_4Chn,

        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT656,
        .stDevCfg.stVicCfg.enPclkSm = VISS_DDR,
        .stDevCfg.stVicCfg.u32IoInv = PCLK_INV,
        .stDevCfg.stVicCfg.eYcSync  = VISS_L8,

        .stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0,
    },
    {
        .enSnsType                  = TP9930_DVP_1920_1080_30FPS_2CH_BT656_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .stSize                     = {1920, 1080},
        .u32ModuleClk               = 198000000,
        .u32Mclock                  = 27000000,
        .u32FrameRate               = 30,
        .astRegCfgs[0].pstRegs      = s_a2ch1080p30fpsBt656,
        .astRegCfgs[0].u32RegsCnt   = ARRAY_SIZE(s_a2ch1080p30fpsBt656),
        .enYuvSeq                   = VISS_YUV_SEQ_C0C1C2C3,
        .enWorkMode                 = VISS_WORK_MODE_2Chn,

        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT656,
        .stDevCfg.stVicCfg.enPclkSm = VISS_DDR,
        .stDevCfg.stVicCfg.u32IoInv = PCLK_INV,
        .stDevCfg.stVicCfg.eYcSync  = VISS_L8,

        .stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0,
    },
    {
        .enSnsType                  = TP9930_DVP_1920_1080_25FPS_2CH_BT656_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .stSize                     = {1920, 1080},
        .u32ModuleClk               = 198000000,
        .u32Mclock                  = 27000000,
        .u32FrameRate               = 25,
        .astRegCfgs[0].pstRegs      = s_a2ch1080p25fpsBt656,
        .astRegCfgs[0].u32RegsCnt   = ARRAY_SIZE(s_a2ch1080p25fpsBt656),
        .enYuvSeq                   = VISS_YUV_SEQ_C0C1C2C3,
        .enWorkMode                 = VISS_WORK_MODE_2Chn,

        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT656,
        .stDevCfg.stVicCfg.enPclkSm = VISS_DDR,
        .stDevCfg.stVicCfg.u32IoInv = PCLK_INV,
        .stDevCfg.stVicCfg.eYcSync  = VISS_L8,

        .stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0,
    },
    {
        .enSnsType                  = TP9930_DVP_1080P_720P_30FPS_2CH_BT656_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .enRgbSeq                   = VISS_YUV_SEQ_C0C1C2C3,
        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT656,
        .stDevCfg.stVicCfg.enPclkSm = VISS_DDR,
        .enWorkMode                 = VISS_WORK_MODE_2Chn,
        .u32ModuleClk               = 148500000,

        .u32Mclock                  = 27000000,
        .u32FrameRate               = 30,

        .stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 1,

    },
    {
        .enSnsType                  = TP9930_DVP_1080P_720P_25FPS_2CH_BT656_YUV,
        .enPixelFormat              = PIX_FMT_YUV_SEMIPLANAR_420,
        .enRgbSeq                   = VISS_YUV_SEQ_C0C1C2C3,
        .stDevCfg.stVicCfg.eDvpType = VISS_DVP_BT656,
        .stDevCfg.stVicCfg.enPclkSm = VISS_DDR,
        .enWorkMode                 = VISS_WORK_MODE_2Chn,
        .u32ModuleClk               = 148500000,

        .u32Mclock                  = 27000000,
        .u32FrameRate               = 25,

        .stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0,
        .stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 1,

    }
};

static void CAMERA_Bt656DecoderPllReset(VISS_DEV dev)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);

    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, 0x20);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3d, 0xe0);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3d, 0x60);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, 0x25);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x40);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x7a, 0x20);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3c, 0x20);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3c, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x7a, 0x25);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x44, 0x07);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x43, 0x12);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x45, 0x09);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf4, 0xa0);

    return ;
}

static void CAMERA_Bt656DecoderInit(VISS_DEV dev)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);

    /* use 4ch 720p@25fps fix config */

    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x02, 0xcc);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x05, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x06, 0x32);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x07, 0x80);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x08, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x09, 0x24);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0a, 0x48);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0b, 0xc0);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0c, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0d, 0x73);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x10, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x11, 0x40);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x12, 0x40);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x13, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x14, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x15, 0x01);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x16, 0xf0);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x17, 0x80);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x18, 0x2a);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x19, 0x38);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1a, 0x47);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1c, 0x0a);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1d, 0x50);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x20, 0x3c);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x21, 0x46);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x22, 0x36);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x23, 0x3c);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x24, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x25, 0xfe);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x26, 0x0d);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x27, 0x2d);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x28, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x29, 0x48);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2a, 0x30);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2b, 0x60);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2c, 0x3a);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2d, 0x54);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2e, 0x40);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x30, 0xa5);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x31, 0x86);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x32, 0xfb);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x33, 0x60);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x35, 0x05);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x36, 0xca);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x38, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x39, 0x1c);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3a, 0x32);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, 0x26);
    //channel ID
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x12);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x13);
    //output format
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4f, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x50, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x52, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf1, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf2, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf3, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf5, 0xf0);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x01);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf8, 0x23);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfa, 0x88);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfb, 0x88);
    //output enable
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4d, 0x07);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4E, 0x05);

}

static void CAMERA_Bt656DecoderCfg(VISS_DEV dev, EI_U8 u8Ch, EI_U8 u8Fmt)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);

    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, (0x00 + u8Ch));

    if (u8Fmt == TYPE_720P25) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x02, 0xce);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x05, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x06, 0x32);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x07, 0xc0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x08, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x09, 0x24);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0a, 0x48);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0b, 0xc0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0c, 0x13);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0d, 0x71);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0e, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0f, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x10, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x11, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x12, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x13, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x14, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x15, 0x13);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x16, 0x16);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x17, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x18, 0x1b);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x19, 0xd0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1a, 0x25);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1b, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1c, 0x07);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1d, 0xbc);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1e, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1f, 0x06);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x20, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x21, 0x46);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x22, 0x36);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x23, 0x3c);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x24, 0x04);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x25, 0xfe);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x26, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x27, 0x2d);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x28, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x29, 0x48);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2a, 0x30);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2b, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2c, 0x3a);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2d, 0x5a);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2e, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2f, 0x06);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x30, 0x9e);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x31, 0x20);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x32, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x33, 0x90);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x35, 0x25);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x36, 0xca);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x37, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x38, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x39, 0x18);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3a, 0x32);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, 0x26);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3c, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3d, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3e, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3f, 0x00);

    } else if (u8Fmt == TYPE_720P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x02, 0xce);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x05, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x06, 0x32);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x07, 0xc0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x08, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x09, 0x24);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0a, 0x48);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0b, 0xc0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0c, 0x13);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0d, 0x70);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0e, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0f, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x10, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x11, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x12, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x13, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x14, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x15, 0x13);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x16, 0x16);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x17, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x18, 0x1b);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x19, 0xd0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1a, 0x25);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1b, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1c, 0x06);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1d, 0x72);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1e, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1f, 0x06);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x20, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x21, 0x46);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x22, 0x36);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x23, 0x3c);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x24, 0x04);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x25, 0xfe);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x26, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x27, 0x2d);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x28, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x29, 0x48);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2a, 0x30);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2b, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2c, 0x3a);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2d, 0x5a);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2e, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2f, 0x06);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x30, 0x9d);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x31, 0xca);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x32, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x33, 0xd0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x35, 0x25);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x36, 0xca);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x37, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x38, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x39, 0x18);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3a, 0x32);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, 0x26);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3c, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3d, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3e, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3f, 0x00);

    } else if (u8Fmt == TYPE_1080P25) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x02, 0xcc);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x05, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x06, 0x32);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x07, 0x80);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x08, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x09, 0x24);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0a, 0x48);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0b, 0xc0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0c, 0x03);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0d, 0x73);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x10, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x11, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x12, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x13, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x14, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x15, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x16, 0xf0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x17, 0x80);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x18, 0x2a);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x19, 0x38);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1a, 0x47);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1c, 0x0a);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1d, 0x50);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x20, 0x3c);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x21, 0x46);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x22, 0x36);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x23, 0x3c);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x24, 0x04);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x25, 0xfe);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x26, 0x0d);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x27, 0x2d);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x28, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x29, 0x48);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2a, 0x30);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2b, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2c, 0x3a);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2d, 0x54);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2e, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x30, 0xa5);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x31, 0x86);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x32, 0xfb);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x33, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x35, 0x05);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x36, 0xca);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x38, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x39, 0x1c);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3a, 0x32);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, 0x26);

    } else if (u8Fmt == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x02, 0xcc);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x05, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x06, 0x32);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x07, 0x80);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x08, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x09, 0x24);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0a, 0x48);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0b, 0xc0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0c, 0x03);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0d, 0x72);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0e, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0f, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x10, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x11, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x12, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x13, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x14, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x15, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x16, 0xf0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x17, 0x80);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x18, 0x2a);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x19, 0x38);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1a, 0x47);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1c, 0x08);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1d, 0x98);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x20, 0x38);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x21, 0x46);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x22, 0x36);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x23, 0x3c);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x24, 0x04);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x25, 0xfe);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x26, 0x0d);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x27, 0x2d);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x28, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x29, 0x48);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2a, 0x30);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2b, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2c, 0x3a);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2d, 0x54);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2e, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x30, 0xa5);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x31, 0x95);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x32, 0xe0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x33, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x35, 0x05);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x36, 0xca);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x38, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x39, 0x1c);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3a, 0x32);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, 0x26);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3c, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3d, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3e, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3f, 0x00);

    }

    return;
}

static void CAMERA_Bt656DecoderMuxCfg1(VISS_DEV dev, EI_U8 *u8ChFormat)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);

    //720P+1080P MUX
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x46, 0x0a);
    //1080P CH-1/CH-3, 720 CH-2/CH-4
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x47, 0x0a); /* only useful for VD1 (see SCH PDF) */
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x49, 0x0a); /* only useful for VD2 (see SCH PDF) */

    //channel ID
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);

    //output format
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4f, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x50, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x52, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf1, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf2, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf3, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf5, 0xfa);
    if ((u8ChFormat[0] == TYPE_1080P30 || u8ChFormat[0] == TYPE_1080P25) &&
        (u8ChFormat[1] == TYPE_720P30 || u8ChFormat[1] == TYPE_720P25)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x01); /* only useful for VD1 (see SCH PDF) */
    } else if ((u8ChFormat[2] == TYPE_1080P30 || u8ChFormat[2] == TYPE_1080P25) &&
        (u8ChFormat[3] == TYPE_720P30 || u8ChFormat[3] == TYPE_720P25)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x23);
    } else {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x01);
    }
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf8, 0x23); /* only useful for VD2 (see SCH PDF) */
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfa, 0x88);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfb, 0x88);
    //output enable
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4d, 0x07);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4E, 0x05);

}

static void CAMERA_Bt656DecoderMuxCfg2(VISS_DEV dev, EI_U8 *u8ChFormat)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);

    //720P+1080P MUX
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x46, 0x05);
    //1080P CH-2/CH-4, 720 CH-1/CH-3
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x47, 0x05);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x49, 0x00);

    //channel ID
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    //output format
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4f, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x50, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x52, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf1, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf2, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf3, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf5, 0xf5);
    if ((u8ChFormat[0] == TYPE_720P30 || u8ChFormat[0] == TYPE_720P25) &&
        (u8ChFormat[1] == TYPE_1080P30 || u8ChFormat[1] == TYPE_1080P25)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x01);
    } else if ((u8ChFormat[2] == TYPE_720P30 || u8ChFormat[2] == TYPE_720P25) &&
        (u8ChFormat[3] == TYPE_1080P30 || u8ChFormat[3] == TYPE_1080P25)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x23);
    } else {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x01);
    }
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf8, 0x23);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfa, 0x88);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfb, 0x88);
    //output enable
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4d, 0x07);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4E, 0x05);
}

static void CAMERA_Bt656DecoderMuxCfg3(VISS_DEV dev, EI_U8 *u8ChFormat)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);

    //720P+1080P MUX
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x46, 0x0c);
    //1080P CH-1/CH-2, 720 CH-3/CH-4
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x47, 0x0c);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x49, 0x00);

    //channel ID
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    //output format
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4f, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x50, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x52, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf1, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf2, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf3, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf5, 0xfc);
    if ((u8ChFormat[0] == TYPE_1080P30 || u8ChFormat[0] == TYPE_1080P25) &&
        (u8ChFormat[2] == TYPE_720P30 || u8ChFormat[2] == TYPE_720P25)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x02);
    } else if ((u8ChFormat[1] == TYPE_1080P30 || u8ChFormat[1] == TYPE_1080P25) &&
        (u8ChFormat[3] == TYPE_720P30 || u8ChFormat[3] == TYPE_720P25)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x13);
    } else if ((u8ChFormat[0] == TYPE_1080P30 || u8ChFormat[0] == TYPE_1080P25) &&
        (u8ChFormat[3] == TYPE_720P30 || u8ChFormat[3] == TYPE_720P25)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x03);
    } else if ((u8ChFormat[1] == TYPE_1080P30 || u8ChFormat[1] == TYPE_1080P25) &&
        (u8ChFormat[2] == TYPE_720P30 || u8ChFormat[2] == TYPE_720P25)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x12);
    } else {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x02);
    }
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf8, 0x23);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfa, 0x88);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfb, 0x88);
    //output enable
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4d, 0x07);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4E, 0x05);
}

static void CAMERA_Bt656DecoderMuxCfg4(VISS_DEV dev, EI_U8 *u8ChFormat)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);

    //720P+1080P MUX
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x46, 0x03);
    //1080P CH-3/CH-4, 720 CH-1/CH-2
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x47, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x49, 0x00);

    //channel ID
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    //output format
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4f, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x50, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x52, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf1, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf2, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf3, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf5, 0xf3);
    if ((u8ChFormat[0] == TYPE_720P30 || u8ChFormat[0] == TYPE_720P25) &&
        (u8ChFormat[2] == TYPE_1080P30 || u8ChFormat[2] == TYPE_1080P25)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x02);
    } else if ((u8ChFormat[1] == TYPE_720P30 || u8ChFormat[1] == TYPE_720P25) &&
        (u8ChFormat[3] == TYPE_1080P30 || u8ChFormat[3] == TYPE_1080P25)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x13);
    } else if ((u8ChFormat[0] == TYPE_720P30 || u8ChFormat[0] == TYPE_720P25) &&
        (u8ChFormat[3] == TYPE_1080P30 || u8ChFormat[3] == TYPE_1080P25)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x03);
    } else if ((u8ChFormat[1] == TYPE_720P30 || u8ChFormat[1] == TYPE_720P25) &&
        (u8ChFormat[2] == TYPE_1080P30 || u8ChFormat[2] == TYPE_1080P25)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x12);
    } else {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x02);
    }
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf8, 0x23);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfa, 0x88);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfb, 0x88);
    //output enable
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4d, 0x07);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4E, 0x05);
}

static void CAMERA_Bt656DecoderMuxCfg5(VISS_DEV dev, EI_U8 *u8ChFormat)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);

    //channel ID
    if ((u8ChFormat[0] == TYPE_1080P25 || u8ChFormat[0] == TYPE_1080P30) &&
        (u8ChFormat[1] == TYPE_1080P25 || u8ChFormat[1] == TYPE_1080P30)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    } else if ((u8ChFormat[0] == TYPE_1080P25 || u8ChFormat[0] == TYPE_1080P30) &&
        (u8ChFormat[2] == TYPE_1080P25 || u8ChFormat[2] == TYPE_1080P30)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    } else if ((u8ChFormat[0] == TYPE_1080P25 || u8ChFormat[0] == TYPE_1080P30) &&
        (u8ChFormat[3] == TYPE_1080P25 || u8ChFormat[3] == TYPE_1080P30)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    } else if ((u8ChFormat[1] == TYPE_1080P25 || u8ChFormat[1] == TYPE_1080P30) &&
        (u8ChFormat[2] == TYPE_1080P25 || u8ChFormat[2] == TYPE_1080P30)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    } else if ((u8ChFormat[1] == TYPE_1080P25 || u8ChFormat[1] == TYPE_1080P30) &&
        (u8ChFormat[3] == TYPE_1080P25 || u8ChFormat[3] == TYPE_1080P30)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    } else if ((u8ChFormat[2] == TYPE_1080P25 || u8ChFormat[2] == TYPE_1080P30) &&
        (u8ChFormat[3] == TYPE_1080P25 || u8ChFormat[3] == TYPE_1080P30)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    }

    //output format
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4f, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x50, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x52, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf1, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf2, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf3, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf5, 0xf0);
    if ((u8ChFormat[0] == TYPE_1080P25 || u8ChFormat[0] == TYPE_1080P30) &&
        (u8ChFormat[1] == TYPE_1080P25 || u8ChFormat[1] == TYPE_1080P30)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x01);
    } else if ((u8ChFormat[0] == TYPE_1080P25 || u8ChFormat[0] == TYPE_1080P30) &&
        (u8ChFormat[2] == TYPE_1080P25 || u8ChFormat[2] == TYPE_1080P30)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x02);
    } else if ((u8ChFormat[0] == TYPE_1080P25 || u8ChFormat[0] == TYPE_1080P30) &&
        (u8ChFormat[3] == TYPE_1080P25 || u8ChFormat[3] == TYPE_1080P30)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x03);
    } else if ((u8ChFormat[1] == TYPE_1080P25 || u8ChFormat[1] == TYPE_1080P30) &&
        (u8ChFormat[2] == TYPE_1080P25 || u8ChFormat[2] == TYPE_1080P30)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x12);
    } else if ((u8ChFormat[1] == TYPE_1080P25 || u8ChFormat[1] == TYPE_1080P30) &&
        (u8ChFormat[3] == TYPE_1080P25 || u8ChFormat[3] == TYPE_1080P30)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x13);
    } else if ((u8ChFormat[2] == TYPE_1080P25 || u8ChFormat[2] == TYPE_1080P30) &&
        (u8ChFormat[3] == TYPE_1080P25 || u8ChFormat[3] == TYPE_1080P30)) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x23);
    }
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf8, 0x23);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfa, 0x88);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfb, 0x88);
    //output enable
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4d, 0x07);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4e, 0x05);

}

static void CAMERA_Bt656DecoderMuxCfg6(VISS_DEV dev, EI_U8 *u8ChFormat)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);

    //channel ID
    if (u8ChFormat[0] == TYPE_1080P25 || u8ChFormat[0] == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    } else if (u8ChFormat[1] == TYPE_1080P25 || u8ChFormat[1] == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    } else if (u8ChFormat[2] == TYPE_1080P25 || u8ChFormat[2] == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    } else if (u8ChFormat[3] == TYPE_1080P25 || u8ChFormat[3] == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
    }

    //output format
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4f, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x50, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x52, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf1, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf2, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf3, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf5, 0xf0);
    if (u8ChFormat[0] == TYPE_1080P25 || u8ChFormat[0] == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x00);
    } else if (u8ChFormat[1] == TYPE_1080P25 || u8ChFormat[1] == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x11);
    } else if (u8ChFormat[2] == TYPE_1080P25 || u8ChFormat[2] == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x22);
    } else if (u8ChFormat[3] == TYPE_1080P25 || u8ChFormat[3] == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x33);
    }
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf8, 0x23);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfa, 0x88);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfb, 0x88);
    //output enable
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4d, 0x07);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4e, 0x05);

}

static EI_S32 CAMERA_Bt656DecoderStart(VISS_DEV dev)
{
    SNS_STATE_S *pstSnsState = EI_NULL;
    EI_U8 u8VinCH = 0x00;
    EI_U8 u8VinCHFormat[4] = {0};
    EI_U8 u8ResType = 0x00;
    EI_U8 u8Count = 0;
    EI_U8 u8Ahd720p25fpsCount = 0;
    EI_U8 u8Ahd720p30fpsCount = 0;
    EI_U8 u8Ahd1080p25fpsCount = 0;
    EI_U8 u8Ahd1080p30fpsCount = 0;
    EI_U8 u8ChRes720pCount = 0;
    EI_U8 u8ChRes1080pCount = 0;
    EI_U8 u8AllChIs720P = 4;

    SNS_GET_CTX(dev, pstSnsState);
    CAMERA_CHECK_POINTER(pstSnsState);

    CAMERA_Bt656DecoderPllReset(dev);
    CAMERA_Bt656DecoderInit(dev);
    ei_msleep(1500); /* must delay */

    for (u8VinCH = 0; u8VinCH < VISS_DEV_MAX_CHN_NUM; u8VinCH++) {
        u8Ahd720p25fpsCount = 0;
        u8Ahd720p30fpsCount = 0;
        u8Ahd1080p25fpsCount = 0;
        u8Ahd1080p30fpsCount = 0;
        EI_PRINT("@@ CH %d ----> format: ", u8VinCH);
        for (u8Count = 0; u8Count < 10; u8Count++) { /* Count 10 to avoid misjudge format */
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, (0x00 + u8VinCH));
            pstSnsState->stI2cInfo.pfnReadReg(pstSnsState, 0x03, &u8ResType);
            EI_PRINT("0x%x ", u8ResType);
            if ((u8ResType & 0x07) == TYPE_720P25) {
                u8Ahd720p25fpsCount++;
            } else if ((u8ResType & 0x07) == TYPE_720P30) {
                u8Ahd720p30fpsCount++;
            } else if ((u8ResType & 0x07) == TYPE_1080P25) {
                u8Ahd1080p25fpsCount++;
            } else if ((u8ResType & 0x07) == TYPE_1080P30) {
                u8Ahd1080p30fpsCount++;
            }
        }
        EI_PRINT("\n");
        if (u8Ahd720p25fpsCount >= 5) { /* 720p25 must 50% accurecy ! */
            u8ResType = TYPE_720P25;
        } else if (u8Ahd720p30fpsCount >= 5) { /* 720p30 must 50% accurecy ! */
            u8ResType = TYPE_720P30;
        } else if (u8Ahd1080p25fpsCount >= 5) { /* 1080p25 must 50% accurecy ! */
            u8ResType = TYPE_1080P25;
        } else if (u8Ahd1080p30fpsCount >= 5) { /* 1080p30 must 50% accurecy ! */
            u8ResType = TYPE_1080P30;
        } else {
            u8ResType = 0;
            EI_PRINT("@@ CH %d ----> Warning! no camera \n", u8VinCH);
        }

        u8VinCHFormat[u8VinCH] = u8ResType;

        switch (u8ResType) {
            case TYPE_720P25:
                EI_PRINT("@@ CH %d ----> 720P@25 \n", u8VinCH);
                CAMERA_Bt656DecoderCfg(dev, u8VinCH, TYPE_720P25);
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1280;
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 720;
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 25;
                if (u8VinCH == 0) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 1;
                } else if (u8VinCH == 1) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
                } else if (u8VinCH == 2) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 1;
                } else if (u8VinCH == 3) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 1;
                }
                u8ChRes720pCount++;
                break;
            case TYPE_720P30:
                EI_PRINT("@@ CH %d ----> 720P@30 \n", u8VinCH);
                CAMERA_Bt656DecoderCfg(dev, u8VinCH, TYPE_720P30);
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1280;
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 720;
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 30;
                if (u8VinCH == 0) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 1;
                } else if (u8VinCH == 1) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
                } else if (u8VinCH == 2) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 1;
                } else if (u8VinCH == 3) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 1;
                }
                u8ChRes720pCount++;
                break;

            case TYPE_1080P25:
                EI_PRINT("@@ CH %d ----> 1080P@25 \n", u8VinCH);
                CAMERA_Bt656DecoderCfg(dev, u8VinCH, TYPE_1080P25);
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 1080;
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 25;
                if (u8VinCH == 0) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
                } else if (u8VinCH == 1) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
                } else if (u8VinCH == 2) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0;
                } else if (u8VinCH == 3) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0;
                }
                u8ChRes1080pCount++;
                break;
            case TYPE_1080P30:
                EI_PRINT("@@ CH %d ----> 1080P@30 \n", u8VinCH);
                CAMERA_Bt656DecoderCfg(dev, u8VinCH, TYPE_1080P30);
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 1080;
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 30;
                if (u8VinCH == 0) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
                } else if (u8VinCH == 1) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
                } else if (u8VinCH == 2) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0;
                } else if (u8VinCH == 3) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0;
                }
                u8ChRes1080pCount++;
                break;
            default:
                EI_PRINT("@@ CH %d ----> Defalut 720P@25 \n", u8VinCH);
                CAMERA_Bt656DecoderCfg(dev, u8VinCH, TYPE_720P25);
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1280;
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 720;
                pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 25;
                if (u8VinCH == 0) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 1;
                } else if (u8VinCH == 1) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
                } else if (u8VinCH == 2) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 1;
                } else if (u8VinCH == 3) {
                    s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 1;
                }
                u8ChRes720pCount++;
                break;
        }

        if ((u8ChRes1080pCount == 1 && u8ChRes720pCount == 1) ||
            (u8ChRes1080pCount == 2)) {

            s_astSnsAttr[0].enWorkMode = 2;
            if (((u8VinCHFormat[0] == TYPE_1080P30 || u8VinCHFormat[0] == TYPE_1080P25) &&
                (u8VinCHFormat[1] == TYPE_720P30 || u8VinCHFormat[1] == TYPE_720P25)) ||
                ((u8VinCHFormat[2] == TYPE_1080P30 || u8VinCHFormat[2] == TYPE_1080P25) &&
                (u8VinCHFormat[3] == TYPE_720P30 || u8VinCHFormat[3] == TYPE_720P25))) {
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 1080;
                if (u8VinCHFormat[0] == TYPE_1080P30 || u8VinCHFormat[2] == TYPE_1080P30) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Width = 1280;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Height = 720;
                if (u8VinCHFormat[1] == TYPE_720P30 || u8VinCHFormat[3] == TYPE_720P30) {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
                EI_PRINT("@@ ----> CAMERA_Bt656DecoderMuxCfg1 \n");
                CAMERA_Bt656DecoderMuxCfg1(dev, u8VinCHFormat);
            }

            if (((u8VinCHFormat[0] == TYPE_720P30 || u8VinCHFormat[0] == TYPE_720P25) &&
                (u8VinCHFormat[1] == TYPE_1080P30 || u8VinCHFormat[1] == TYPE_1080P25)) ||
                ((u8VinCHFormat[2] == TYPE_720P30 || u8VinCHFormat[2] == TYPE_720P25) &&
                (u8VinCHFormat[3] == TYPE_1080P30 || u8VinCHFormat[3] == TYPE_1080P25))) {
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1280;
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 720;
                if (u8VinCHFormat[0] == TYPE_720P30 || u8VinCHFormat[1] == TYPE_720P30) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 1;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Height = 1080;
                if (u8VinCHFormat[1] == TYPE_1080P30 || u8VinCHFormat[3] == TYPE_1080P30) {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
                EI_PRINT("@@ ----> CAMERA_Bt656DecoderMuxCfg2 \n");
                CAMERA_Bt656DecoderMuxCfg2(dev, u8VinCHFormat);
            }

            if (((u8VinCHFormat[0] == TYPE_1080P30 || u8VinCHFormat[0] == TYPE_1080P25) &&
                (u8VinCHFormat[2] == TYPE_720P30 || u8VinCHFormat[2] == TYPE_720P25)) ||
                ((u8VinCHFormat[1] == TYPE_1080P30 || u8VinCHFormat[1] == TYPE_1080P25) &&
                (u8VinCHFormat[3] == TYPE_720P30 || u8VinCHFormat[3] == TYPE_720P25)) ||
                ((u8VinCHFormat[0] == TYPE_1080P30 || u8VinCHFormat[0] == TYPE_1080P25) &&
                (u8VinCHFormat[3] == TYPE_720P30 || u8VinCHFormat[3] == TYPE_720P25)) ||
                ((u8VinCHFormat[1] == TYPE_1080P30 || u8VinCHFormat[1] == TYPE_1080P25) &&
                (u8VinCHFormat[2] == TYPE_720P30 || u8VinCHFormat[2] == TYPE_720P25))) {
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 1080;
                if (u8VinCHFormat[0] == TYPE_1080P30 || u8VinCHFormat[1] == TYPE_1080P30) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Width = 1280;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Height = 720;
                if (u8VinCHFormat[2] == TYPE_720P30 || u8VinCHFormat[3] == TYPE_720P30) {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
                EI_PRINT("@@ ----> CAMERA_Bt656DecoderMuxCfg3 \n");
                CAMERA_Bt656DecoderMuxCfg3(dev, u8VinCHFormat);
            }

            if (((u8VinCHFormat[0] == TYPE_720P30 || u8VinCHFormat[0] == TYPE_720P25) &&
                (u8VinCHFormat[2] == TYPE_1080P30 || u8VinCHFormat[2] == TYPE_1080P25)) ||
                ((u8VinCHFormat[1] == TYPE_720P30 || u8VinCHFormat[1] == TYPE_720P25) &&
                (u8VinCHFormat[3] == TYPE_1080P30 || u8VinCHFormat[3] == TYPE_1080P25)) ||
                ((u8VinCHFormat[0] == TYPE_720P30 || u8VinCHFormat[0] == TYPE_720P25) &&
                (u8VinCHFormat[3] == TYPE_1080P30 || u8VinCHFormat[3] == TYPE_1080P25)) ||
                ((u8VinCHFormat[1] == TYPE_720P30 || u8VinCHFormat[1] == TYPE_720P25) &&
                (u8VinCHFormat[2] == TYPE_1080P30 || u8VinCHFormat[2] == TYPE_1080P25))) {
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1280;
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 720;
                if (u8VinCHFormat[0] == TYPE_720P30 || u8VinCHFormat[1] == TYPE_720P30) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 1;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Height = 1080;
                if (u8VinCHFormat[2] == TYPE_1080P30 || u8VinCHFormat[3] == TYPE_1080P30) {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
                EI_PRINT("@@ ----> CAMERA_Bt656DecoderMuxCfg4 \n");
                CAMERA_Bt656DecoderMuxCfg4(dev, u8VinCHFormat);
            }

            if (((u8VinCHFormat[0] == TYPE_1080P30 || u8VinCHFormat[0] == TYPE_1080P25) &&
                (u8VinCHFormat[1] == TYPE_1080P30 || u8VinCHFormat[1] == TYPE_1080P25)) ||
                ((u8VinCHFormat[0] == TYPE_1080P30 || u8VinCHFormat[0] == TYPE_1080P25) &&
                (u8VinCHFormat[2] == TYPE_1080P30 || u8VinCHFormat[2] == TYPE_1080P25)) ||
                ((u8VinCHFormat[0] == TYPE_1080P30 || u8VinCHFormat[0] == TYPE_1080P25) &&
                (u8VinCHFormat[3] == TYPE_1080P30 || u8VinCHFormat[3] == TYPE_1080P25)) ||
                ((u8VinCHFormat[1] == TYPE_1080P30 || u8VinCHFormat[1] == TYPE_1080P25) &&
                (u8VinCHFormat[2] == TYPE_1080P30 || u8VinCHFormat[2] == TYPE_1080P25)) ||
                ((u8VinCHFormat[1] == TYPE_1080P30 || u8VinCHFormat[1] == TYPE_1080P25) &&
                (u8VinCHFormat[3] == TYPE_1080P30 || u8VinCHFormat[3] == TYPE_1080P25)) ||
                ((u8VinCHFormat[2] == TYPE_1080P30 || u8VinCHFormat[2] == TYPE_1080P25) &&
                (u8VinCHFormat[3] == TYPE_1080P30 || u8VinCHFormat[3] == TYPE_1080P25))) {
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 1080;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Height = 1080;
                if ((u8VinCHFormat[0] == TYPE_1080P30 && u8VinCHFormat[1] == TYPE_1080P25) ||
                    (u8VinCHFormat[0] == TYPE_1080P30 && u8VinCHFormat[2] == TYPE_1080P25) ||
                    (u8VinCHFormat[0] == TYPE_1080P30 && u8VinCHFormat[3] == TYPE_1080P25) ||
                    (u8VinCHFormat[1] == TYPE_1080P30 && u8VinCHFormat[2] == TYPE_1080P25) ||
                    (u8VinCHFormat[1] == TYPE_1080P30 && u8VinCHFormat[3] == TYPE_1080P25) ||
                    (u8VinCHFormat[2] == TYPE_1080P30 && u8VinCHFormat[3] == TYPE_1080P25)) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
                } else if ((u8VinCHFormat[0] == TYPE_1080P25 && u8VinCHFormat[1] == TYPE_1080P30) ||
                    (u8VinCHFormat[0] == TYPE_1080P25 && u8VinCHFormat[2] == TYPE_1080P30) ||
                    (u8VinCHFormat[0] == TYPE_1080P25 && u8VinCHFormat[3] == TYPE_1080P30) ||
                    (u8VinCHFormat[1] == TYPE_1080P25 && u8VinCHFormat[2] == TYPE_1080P30) ||
                    (u8VinCHFormat[1] == TYPE_1080P25 && u8VinCHFormat[3] == TYPE_1080P30) ||
                    (u8VinCHFormat[2] == TYPE_1080P25 && u8VinCHFormat[3] == TYPE_1080P30)) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
                } else if ((u8VinCHFormat[0] == TYPE_1080P30 && u8VinCHFormat[1] == TYPE_1080P30) ||
                    (u8VinCHFormat[0] == TYPE_1080P30 && u8VinCHFormat[2] == TYPE_1080P30) ||
                    (u8VinCHFormat[0] == TYPE_1080P30 && u8VinCHFormat[3] == TYPE_1080P30) ||
                    (u8VinCHFormat[1] == TYPE_1080P30 && u8VinCHFormat[2] == TYPE_1080P30) ||
                    (u8VinCHFormat[1] == TYPE_1080P30 && u8VinCHFormat[3] == TYPE_1080P30) ||
                    (u8VinCHFormat[2] == TYPE_1080P30 && u8VinCHFormat[3] == TYPE_1080P30)) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
                } else if ((u8VinCHFormat[0] == TYPE_1080P25 && u8VinCHFormat[1] == TYPE_1080P25) ||
                    (u8VinCHFormat[0] == TYPE_1080P25 && u8VinCHFormat[2] == TYPE_1080P25) ||
                    (u8VinCHFormat[0] == TYPE_1080P25 && u8VinCHFormat[3] == TYPE_1080P25) ||
                    (u8VinCHFormat[1] == TYPE_1080P25 && u8VinCHFormat[2] == TYPE_1080P25) ||
                    (u8VinCHFormat[1] == TYPE_1080P25 && u8VinCHFormat[3] == TYPE_1080P25) ||
                    (u8VinCHFormat[2] == TYPE_1080P25 && u8VinCHFormat[3] == TYPE_1080P25)) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
                EI_PRINT("@@ ----> CAMERA_Bt656DecoderMuxCfg5 \n");
                CAMERA_Bt656DecoderMuxCfg5(dev, u8VinCHFormat);
            }

            return EI_SUCCESS;
        }
    }

    if (u8ChRes1080pCount == 1) {
        s_astSnsAttr[0].enWorkMode = 1;
        s_astSnsAttr[0].stDevCfg.stVicCfg.enPclkSm = VISS_SDR;
        s_astSnsAttr[0].stSize.u32Width = 1920;
        s_astSnsAttr[0].stSize.u32Height = 1080;
        pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1920;
        pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 1080;
        if (u8VinCHFormat[0] == TYPE_1080P30 ||
            u8VinCHFormat[1] == TYPE_1080P30 ||
            u8VinCHFormat[2] == TYPE_1080P30 ||
            u8VinCHFormat[3] == TYPE_1080P30) {
            pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
        } else {
            pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
        }
        EI_PRINT("@@ ----> CAMERA_Bt656DecoderMuxCfg6 \n");
        CAMERA_Bt656DecoderMuxCfg6(dev, u8VinCHFormat);
        return EI_SUCCESS;
    }

    if (u8ChRes720pCount == u8AllChIs720P) {
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0;
    }
    //channel ID
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x12);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x13);
    //output format
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4f, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x50, 0xa3);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x52, 0xa3);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf1, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf2, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf3, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf4, 0x20);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf5, 0xff);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf8, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfa, 0x88);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfb, 0x88);
    //output enable
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4d, 0x07);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4E, 0x05);

    return EI_SUCCESS;

}

static int CAMERA_SetI2cInfo(VISS_DEV dev)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);
    CAMERA_CHECK_POINTER(pstSnsState);

    if (pstSnsState->stI2cInfo.fd > 0) {
        return EI_SUCCESS;
    }

    pstSnsState->stI2cInfo.u8RegBits = 8;
    pstSnsState->stI2cInfo.u8ValBits = 8;
    pstSnsState->stI2cInfo.u16I2cBusNum = 2;
    pstSnsState->stI2cInfo.u16I2cDevAddr = 0x44;
    pstSnsState->pcName = SNS_NAME;

    return EI_SUCCESS;
}

static EI_S32 CAMERA_Detect(VISS_DEV VissDev)
{
    EI_U8 u8Tmp[2];
    EI_S32 s32Ret = EI_SUCCESS;
    EI_U16 u16Id;
    SNS_STATE_S *pstSnsState = EI_NULL;
    I2C_INFO_S *pstI2cInfo = EI_NULL;

    SNS_GET_CTX(VissDev, pstSnsState);

    pstI2cInfo = &pstSnsState->stI2cInfo;

    CAMERA_CHECK_POINTER(pstI2cInfo->pfnReadReg);
    s32Ret = pstI2cInfo->pfnReadReg(pstSnsState, 0xFE, &u8Tmp[0]);
    if (s32Ret != 0) {
        PRT_VISS_ERR("%s tmp[0]=%x\n", SNS_NAME, u8Tmp[0]);
        return s32Ret;
    }
    s32Ret = pstI2cInfo->pfnReadReg(pstSnsState, 0xFF, &u8Tmp[1]);
    if (s32Ret != 0) {
        PRT_VISS_ERR("%s tmp[0]=%x,tmp[1]=%x\n", SNS_NAME, u8Tmp[0], u8Tmp[1]);
        return s32Ret;
    }
    u16Id = (u8Tmp[0] << 8) | u8Tmp[1];
    PRT_VISS_INFO("%s id: 0x%04x\n", SNS_NAME, u16Id);

    if (u16Id != 0x2832) {
        PRT_VISS_ERR("%s ID wrong! (0x%04x != 0x2832)\n", SNS_NAME, u16Id);
        return EI_FAILURE;
    }

    return EI_SUCCESS;
}

static EI_S32 CAMERA_SetAudioVolume(VISS_DEV dev, EI_U32 u32Chn, EI_U8 u8Volume)
{
    SNS_STATE_S *pstSnsState = EI_NULL;
    EI_S32 s32Ret = EI_SUCCESS;
    EI_U8 u8TmpVin12 = 0;
    EI_U8 u8TmpVin34 = 0;
    EI_U8 u8TmpVin5 = 0;
    EI_U8 u8TmpVolume = 0;

    SNS_GET_CTX(dev, pstSnsState);
    CAMERA_CHECK_POINTER(pstSnsState);

    PRT_VISS_INFO("%s audio Ch: %d, Volume: %d", SNS_NAME, u32Chn, u8Volume);

    s32Ret = pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x40);
    if (s32Ret != EI_SUCCESS) {
        PRT_VISS_ERR("%s audio pfnWriteReg err, %d\n", SNS_NAME, s32Ret);
    }
    s32Ret = pstSnsState->stI2cInfo.pfnReadReg(pstSnsState, 0x39, &u8TmpVin12);
    if (s32Ret != EI_SUCCESS) {
        PRT_VISS_ERR("%s audio pfnReadReg err, %d\n", SNS_NAME, s32Ret);
    }
    s32Ret = pstSnsState->stI2cInfo.pfnReadReg(pstSnsState, 0x3a, &u8TmpVin34);
    if (s32Ret != EI_SUCCESS) {
        PRT_VISS_ERR("%s audio pfnReadReg err, %d\n", SNS_NAME, s32Ret);
    }
    s32Ret = pstSnsState->stI2cInfo.pfnReadReg(pstSnsState, 0x3b, &u8TmpVin5);
    if (s32Ret != EI_SUCCESS) {
        PRT_VISS_ERR("%s audio pfnReadReg err, %d\n", SNS_NAME, s32Ret);
    }

    switch (u32Chn) {
        case 0x0:
            u8TmpVolume = (u8Volume | (u8TmpVin34 & 0xF0));
            s32Ret = pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x39, u8TmpVolume);
            if (s32Ret != EI_SUCCESS) {
                PRT_VISS_ERR("%s audio pfnWriteReg err, %d\n", SNS_NAME, s32Ret);
            }
            break;
        case 0x1:
            u8TmpVolume = ((u8Volume << 4) | (u8TmpVin34 & 0x0F));
            s32Ret = pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x39, u8TmpVolume);
            if (s32Ret != EI_SUCCESS) {
                PRT_VISS_ERR("%s audio pfnWriteReg err, %d\n", SNS_NAME, s32Ret);
            }
            break;
        case 0x2:
            u8TmpVolume = (u8Volume | (u8TmpVin34 & 0xF0));
            s32Ret = pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3a, u8TmpVolume);
            if (s32Ret != EI_SUCCESS) {
                PRT_VISS_ERR("%s audio pfnWriteReg err, %d\n", SNS_NAME, s32Ret);
            }
            break;
        case 0x3:
            u8TmpVolume = ((u8Volume << 4) | (u8TmpVin34 & 0x0F));
            s32Ret = pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3a, u8TmpVolume);
            if (s32Ret != EI_SUCCESS) {
                PRT_VISS_ERR("%s audio pfnWriteReg err, %d\n", SNS_NAME, s32Ret);
            }
            break;
        case 0x4:
            u8TmpVolume = (u8Volume | (u8TmpVin5 & 0xF0));
            s32Ret = pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, u8TmpVolume);
            if (s32Ret != EI_SUCCESS) {
                PRT_VISS_ERR("%s audio pfnWriteReg err, %d\n", SNS_NAME, s32Ret);
            }
            break;
        default:
            u8TmpVolume = (u8Volume | (u8Volume << 4));
            s32Ret = pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x39, u8TmpVolume);
            if (s32Ret != EI_SUCCESS) {
                PRT_VISS_ERR("%s audio pfnWriteReg err, %d\n", SNS_NAME, s32Ret);
            }
            s32Ret = pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3a, u8TmpVolume);
            if (s32Ret != EI_SUCCESS) {
                PRT_VISS_ERR("%s audio pfnWriteReg err, %d\n", SNS_NAME, s32Ret);
            }

            u8TmpVolume = (u8Volume | (u8TmpVin5 & 0xF0));
            s32Ret = pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, u8TmpVolume);
            if (s32Ret != EI_SUCCESS) {
                PRT_VISS_ERR("%s audio pfnWriteReg err, %d\n", SNS_NAME, s32Ret);
            }
            break;
    }

    CAMERA_CHECK_SUCCESS(s32Ret);

    return s32Ret;
}

static EI_S32 CAMERA_Stream(VISS_DEV dev, EI_BOOL bOn)
{
    SNS_STATE_S *pstSnsState = EI_NULL;
    EI_S32 s32Ret = EI_SUCCESS;
    SNS_GET_CTX(dev, pstSnsState);
    CAMERA_CHECK_POINTER(pstSnsState);
    EI_U8 u8i = 0;

    PRT_VISS_INFO("%s CAMERA_Stream*******%d\n", SNS_NAME, bOn);

    if (pstSnsState->enSnsInitMode == COMMON_MANUCFG) {
        if ((u8Ch1080pCount == 1 && u8Ch720pCount == 1) ||
            (u8Ch1080pCount == 2)) {

            s_astSnsAttr[0].enWorkMode = 2;
            if (((u8ChFormat[0] == TYPE_1080P30 || u8ChFormat[0] == TYPE_1080P25) &&
                (u8ChFormat[1] == TYPE_720P30 || u8ChFormat[1] == TYPE_720P25)) ||
                ((u8ChFormat[2] == TYPE_1080P30 || u8ChFormat[2] == TYPE_1080P25) &&
                (u8ChFormat[3] == TYPE_720P30 || u8ChFormat[3] == TYPE_720P25))) {
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 1080;
                if (u8ChFormat[0] == TYPE_1080P30 || u8ChFormat[2] == TYPE_1080P30) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Width = 1280;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Height = 720;
                if (u8ChFormat[1] == TYPE_720P30 || u8ChFormat[3] == TYPE_720P30) {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
                EI_PRINT("@@ ----> CAMERA_Bt656DecoderMuxCfg1 \n");
                CAMERA_Bt656DecoderMuxCfg1(dev, u8ChFormat);
                goto STREAM;
            }

            if (((u8ChFormat[0] == TYPE_720P30 || u8ChFormat[0] == TYPE_720P25) &&
                (u8ChFormat[1] == TYPE_1080P30 || u8ChFormat[1] == TYPE_1080P25)) ||
                ((u8ChFormat[2] == TYPE_720P30 || u8ChFormat[2] == TYPE_720P25) &&
                (u8ChFormat[3] == TYPE_1080P30 || u8ChFormat[3] == TYPE_1080P25))) {
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1280;
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 720;
                if (u8ChFormat[0] == TYPE_720P30 || u8ChFormat[1] == TYPE_720P30) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 1;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Height = 1080;
                if (u8ChFormat[1] == TYPE_1080P30 || u8ChFormat[3] == TYPE_1080P30) {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
                EI_PRINT("@@ ----> CAMERA_Bt656DecoderMuxCfg2 \n");
                CAMERA_Bt656DecoderMuxCfg2(dev, u8ChFormat);
                goto STREAM;
            }

            if (((u8ChFormat[0] == TYPE_1080P30 || u8ChFormat[0] == TYPE_1080P25) &&
                (u8ChFormat[2] == TYPE_720P30 || u8ChFormat[2] == TYPE_720P25)) ||
                ((u8ChFormat[1] == TYPE_1080P30 || u8ChFormat[1] == TYPE_1080P25) &&
                (u8ChFormat[3] == TYPE_720P30 || u8ChFormat[3] == TYPE_720P25)) ||
                ((u8ChFormat[0] == TYPE_1080P30 || u8ChFormat[0] == TYPE_1080P25) &&
                (u8ChFormat[3] == TYPE_720P30 || u8ChFormat[3] == TYPE_720P25)) ||
                ((u8ChFormat[1] == TYPE_1080P30 || u8ChFormat[1] == TYPE_1080P25) &&
                (u8ChFormat[2] == TYPE_720P30 || u8ChFormat[2] == TYPE_720P25))) {
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 1080;
                if (u8ChFormat[0] == TYPE_1080P30 || u8ChFormat[1] == TYPE_1080P30) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Width = 1280;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Height = 720;
                if (u8ChFormat[2] == TYPE_720P30 || u8ChFormat[3] == TYPE_720P30) {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
                EI_PRINT("@@ ----> CAMERA_Bt656DecoderMuxCfg3 \n");
                CAMERA_Bt656DecoderMuxCfg3(dev, u8ChFormat);
                goto STREAM;
            }

            if (((u8ChFormat[0] == TYPE_720P30 || u8ChFormat[0] == TYPE_720P25) &&
                (u8ChFormat[2] == TYPE_1080P30 || u8ChFormat[2] == TYPE_1080P25)) ||
                ((u8ChFormat[1] == TYPE_720P30 || u8ChFormat[1] == TYPE_720P25) &&
                (u8ChFormat[3] == TYPE_1080P30 || u8ChFormat[3] == TYPE_1080P25)) ||
                ((u8ChFormat[0] == TYPE_720P30 || u8ChFormat[0] == TYPE_720P25) &&
                (u8ChFormat[3] == TYPE_1080P30 || u8ChFormat[3] == TYPE_1080P25)) ||
                ((u8ChFormat[1] == TYPE_720P30 || u8ChFormat[1] == TYPE_720P25) &&
                (u8ChFormat[2] == TYPE_1080P30 || u8ChFormat[2] == TYPE_1080P25))) {
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1280;
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 720;
                if (u8ChFormat[0] == TYPE_720P30 || u8ChFormat[1] == TYPE_720P30) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 1;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Height = 1080;
                if (u8ChFormat[2] == TYPE_1080P30 || u8ChFormat[3] == TYPE_1080P30) {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
                } else {
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
                EI_PRINT("@@ ----> CAMERA_Bt656DecoderMuxCfg4 \n");
                CAMERA_Bt656DecoderMuxCfg4(dev, u8ChFormat);
                goto STREAM;
            }

            if (((u8ChFormat[0] == TYPE_1080P30 || u8ChFormat[0] == TYPE_1080P25) &&
                (u8ChFormat[1] == TYPE_1080P30 || u8ChFormat[1] == TYPE_1080P25)) ||
                ((u8ChFormat[0] == TYPE_1080P30 || u8ChFormat[0] == TYPE_1080P25) &&
                (u8ChFormat[2] == TYPE_1080P30 || u8ChFormat[2] == TYPE_1080P25)) ||
                ((u8ChFormat[0] == TYPE_1080P30 || u8ChFormat[0] == TYPE_1080P25) &&
                (u8ChFormat[3] == TYPE_1080P30 || u8ChFormat[3] == TYPE_1080P25)) ||
                ((u8ChFormat[1] == TYPE_1080P30 || u8ChFormat[1] == TYPE_1080P25) &&
                (u8ChFormat[2] == TYPE_1080P30 || u8ChFormat[2] == TYPE_1080P25)) ||
                ((u8ChFormat[1] == TYPE_1080P30 || u8ChFormat[1] == TYPE_1080P25) &&
                (u8ChFormat[3] == TYPE_1080P30 || u8ChFormat[3] == TYPE_1080P25)) ||
                ((u8ChFormat[2] == TYPE_1080P30 || u8ChFormat[2] == TYPE_1080P25) &&
                (u8ChFormat[3] == TYPE_1080P30 || u8ChFormat[3] == TYPE_1080P25))) {
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 1080;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Width = 1920;
                pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Height = 1080;
                if ((u8ChFormat[0] == TYPE_1080P30 && u8ChFormat[1] == TYPE_1080P25) ||
                    (u8ChFormat[0] == TYPE_1080P30 && u8ChFormat[2] == TYPE_1080P25) ||
                    (u8ChFormat[0] == TYPE_1080P30 && u8ChFormat[3] == TYPE_1080P25) ||
                    (u8ChFormat[1] == TYPE_1080P30 && u8ChFormat[2] == TYPE_1080P25) ||
                    (u8ChFormat[1] == TYPE_1080P30 && u8ChFormat[3] == TYPE_1080P25) ||
                    (u8ChFormat[2] == TYPE_1080P30 && u8ChFormat[3] == TYPE_1080P25)) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
                } else if ((u8ChFormat[0] == TYPE_1080P25 && u8ChFormat[1] == TYPE_1080P30) ||
                    (u8ChFormat[0] == TYPE_1080P25 && u8ChFormat[2] == TYPE_1080P30) ||
                    (u8ChFormat[0] == TYPE_1080P25 && u8ChFormat[3] == TYPE_1080P30) ||
                    (u8ChFormat[1] == TYPE_1080P25 && u8ChFormat[2] == TYPE_1080P30) ||
                    (u8ChFormat[1] == TYPE_1080P25 && u8ChFormat[3] == TYPE_1080P30) ||
                    (u8ChFormat[2] == TYPE_1080P25 && u8ChFormat[3] == TYPE_1080P30)) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
                } else if ((u8ChFormat[0] == TYPE_1080P30 && u8ChFormat[1] == TYPE_1080P30) ||
                    (u8ChFormat[0] == TYPE_1080P30 && u8ChFormat[2] == TYPE_1080P30) ||
                    (u8ChFormat[0] == TYPE_1080P30 && u8ChFormat[3] == TYPE_1080P30) ||
                    (u8ChFormat[1] == TYPE_1080P30 && u8ChFormat[2] == TYPE_1080P30) ||
                    (u8ChFormat[1] == TYPE_1080P30 && u8ChFormat[3] == TYPE_1080P30) ||
                    (u8ChFormat[2] == TYPE_1080P30 && u8ChFormat[3] == TYPE_1080P30)) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
                } else if ((u8ChFormat[0] == TYPE_1080P25 && u8ChFormat[1] == TYPE_1080P25) ||
                    (u8ChFormat[0] == TYPE_1080P25 && u8ChFormat[2] == TYPE_1080P25) ||
                    (u8ChFormat[0] == TYPE_1080P25 && u8ChFormat[3] == TYPE_1080P25) ||
                    (u8ChFormat[1] == TYPE_1080P25 && u8ChFormat[2] == TYPE_1080P25) ||
                    (u8ChFormat[1] == TYPE_1080P25 && u8ChFormat[3] == TYPE_1080P25) ||
                    (u8ChFormat[2] == TYPE_1080P25 && u8ChFormat[3] == TYPE_1080P25)) {
                    pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
                    pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
                }
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
                EI_PRINT("@@ ----> CAMERA_Bt656DecoderMuxCfg5 \n");
                CAMERA_Bt656DecoderMuxCfg5(dev, u8ChFormat);
                goto STREAM;
            }
        }

        if (u8Ch1080pCount == 1) {
            s_astSnsAttr[0].enWorkMode = 1;
            s_astSnsAttr[0].stDevCfg.stVicCfg.enPclkSm = VISS_SDR;
            s_astSnsAttr[0].stSize.u32Width = 1920;
            s_astSnsAttr[0].stSize.u32Height = 1080;
            pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1920;
            pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 1080;
            if (u8ChFormat[0] == TYPE_1080P30 ||
                u8ChFormat[1] == TYPE_1080P30 ||
                u8ChFormat[2] == TYPE_1080P30 ||
                u8ChFormat[3] == TYPE_1080P30) {
                pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
            } else {
                pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
            }
            EI_PRINT("@@ ----> CAMERA_Bt656DecoderMuxCfg6 \n");
            CAMERA_Bt656DecoderMuxCfg6(dev, u8ChFormat);
            goto STREAM;
        }

        if (u8Ch720pCount == 4) {
            //channel ID
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x12);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x13);
            //output format
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4f, 0x03);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x50, 0xa3);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x52, 0xa3);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf1, 0x04);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf2, 0x77);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf3, 0x77);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf4, 0x20);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf5, 0xff);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x10);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf8, 0x10);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfa, 0x88);
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfb, 0x88);
            //output enable
            pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4d, 0x07);
            goto STREAM;
        }

    }

STREAM:

    u8Count = 0;
    u8Ch720pCount = 0;
    u8Ch1080pCount = 0;
    for (u8i = 0; u8i < 4; u8i++) {
        u8ChFormat[u8i] = 0xff;
    }

    if (bOn) {
        s32Ret = pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4E, 0x05);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("CAMERA_Stream*******%d\n", bOn);
        }
    } else {
        s32Ret = pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4E, 0x00);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("CAMERA_Stream*******%d\n", bOn);
        }
    }

    return s32Ret;
}

/* The following functions can be modified as needed */

static int CAMERA_I2cInit(VISS_DEV dev)
{
    SNS_STATE_S *pstSnsState = EI_NULL;
    int ret = EI_SUCCESS;

    SNS_GET_CTX(dev, pstSnsState);
    CAMERA_CHECK_POINTER(pstSnsState);

    ret = CAMERA_SetI2cInfo(dev);
    CAMERA_CHECK_SUCCESS(ret);

    ret = CAMERA_I2C_Reg_Ops(&pstSnsState->stI2cInfo);
    CAMERA_CHECK_SUCCESS(ret);

    return EI_SUCCESS;
}

static int CAMERA_I2cExit(VISS_DEV dev)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);
    CAMERA_CHECK_POINTER(pstSnsState);

    return EI_SUCCESS;
}

static EI_S32 CAMERA_PowerUp(VISS_DEV VissDev)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(VissDev, pstSnsState);

    MI_VISS_SnsPower(VissDev, 0xa0000000);

    CAMERA_SensorPowerUp(VissDev, pstSnsState);

    return 0;
}

static EI_S32 CAMERA_PowerDown(VISS_DEV VissDev)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(VissDev, pstSnsState);

    MI_VISS_SnsPower(VissDev, 0x00000000);

    CAMERA_SensorPowerDown(VissDev, pstSnsState);

    return 0;
}

static EI_S32 CAMERA_I2cWrite(VISS_DEV VissDev, EI_U32 u32Ch, EI_U32 u32Reg, EI_U32 u32Val)
{
    EI_S32 s32Ret = EI_SUCCESS;
    SNS_STATE_S *pstSnsState = EI_NULL;
    I2C_INFO_S *pstI2cInfo = EI_NULL;
    CAMERA_S *pStCam = EI_NULL;

    SNS_GET_CTX(VissDev, pstSnsState);
    pstI2cInfo = &pstSnsState->stI2cInfo;
    CAMERA_CHECK_POINTER(pstI2cInfo->pfnWriteReg);
    pStCam = (CAMERA_S *)pstSnsState->pCam;

    pthread_mutex_lock(&pStCam->mutex);
    s32Ret += pstI2cInfo->pfnWriteReg(pstSnsState, 0x40, u32Ch);
    s32Ret = pstI2cInfo->pfnWriteReg(pstSnsState, u32Reg, u32Val);
    pthread_mutex_unlock(&pStCam->mutex);

    return s32Ret;
}

static EI_S32 CAMERA_I2cRead(VISS_DEV VissDev, EI_U32 u32Ch, EI_U32 u32Reg, EI_U32 *pu32Val)
{
    EI_S32 s32Ret = EI_SUCCESS;
    SNS_STATE_S *pstSnsState = EI_NULL;
    I2C_INFO_S *pstI2cInfo = EI_NULL;
    CAMERA_S *pStCam = EI_NULL;

    SNS_GET_CTX(VissDev, pstSnsState);
    pstI2cInfo = &pstSnsState->stI2cInfo;
    CAMERA_CHECK_POINTER(pstI2cInfo->pfnReadReg);
    pStCam = (CAMERA_S *)pstSnsState->pCam;

    pthread_mutex_lock(&pStCam->mutex);
    s32Ret += pstI2cInfo->pfnWriteReg(pstSnsState, 0x40, u32Ch);
    s32Ret += pstI2cInfo->pfnReadReg(pstSnsState, u32Reg, pu32Val);
    pthread_mutex_unlock(&pStCam->mutex);

    return s32Ret;
}

static void CAMERA_SetChnFormat(VISS_DEV dev, EI_U8 ch, EI_U8 fmt)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);

    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, (0x00 + ch));
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x02, 0x44);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x07, 0x80);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0b, 0xc0);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0c, 0x03);

    if (fmt == TYPE_720P25) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0d, 0x71);
    } else if (fmt == TYPE_720P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0d, 0x70);
    } else if (fmt == TYPE_1080P25) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0d, 0x73);
    } else if (fmt == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x0d, 0x72);
    }

    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x10, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x11, 0x40);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x12, 0x40);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x13, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x14, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x15, 0x01);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x16, 0xf0);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x17, 0x80);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x18, 0x29);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x19, 0x38);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1a, 0x47);

    if (fmt == TYPE_720P25) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1c, 0x06);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1d, 0x72);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x20, 0x38);
    } else if (fmt == TYPE_720P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1c, 0x0c);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1d, 0xe4);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x20, 0x38);
    } else if (fmt == TYPE_1080P25) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1c, 0x0a);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1d, 0x50);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x20, 0x3c);
    } else if (fmt == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1c, 0x08);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x1d, 0x98);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x20, 0x38);
    }


    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x21, 0x46);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x22, 0x36);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x23, 0x3c);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x24, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x25, 0xfe);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x26, 0x0d);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x27, 0x2d);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x28, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x29, 0x48);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2a, 0x30);
    /* { 0x2a, 0x3c }, */ /* blue screen */
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2b, 0x60);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2c, 0x3a);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2d, 0x54);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x2e, 0x40);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x30, 0xa5);
    if (fmt == TYPE_720P25) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x31, 0x95);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x32, 0xe0);

    } else if (fmt == TYPE_720P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x31, 0x95);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x32, 0xe0);

    } else if (fmt == TYPE_1080P25) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x31, 0x86);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x32, 0xfb);

    } else if (fmt == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x31, 0x95);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x32, 0xe0);

    }

    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x33, 0x60);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x35, 0x05);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x36, 0xca);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x38, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x39, 0x1c);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3a, 0x32);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, 0x26);
    /* cha nnel ID */
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x01);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x11);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x02);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x12);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x34, 0x13);
    /* output format */
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4f, 0x03);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x50, 0xb2);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x52, 0xf6);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf1, 0x04);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf2, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf3, 0x77);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf5, 0xF0);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf6, 0x10);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf8, 0x54);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfa, 0x88);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xfb, 0x88);
    /* output enable */

    if (fmt == TYPE_1080P25) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf3, 0x71);
    } else if (fmt == TYPE_1080P30) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf3, 0x70);
    }
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4d, 0x07);
    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4e, 0x05);


    return;
}

static EI_S32 CAMERA_DecoderInit(VISS_DEV dev)
{
    EI_S32 s32Ret = EI_SUCCESS;

    CAMERA_Bt656DecoderPllReset(dev);
    CAMERA_Bt656DecoderInit(dev);

    return s32Ret;
}

static EI_S32 CAMERA_SetDecoder(VISS_DEV dev, EI_U8 u8VinCH, EI_U8 u8Type, EI_U8 u8std)
{
    SNS_STATE_S *pstSnsState = EI_NULL;
    EI_S32 s32Ret = EI_SUCCESS;

    SNS_GET_CTX(dev, pstSnsState);
    CAMERA_CHECK_POINTER(pstSnsState);

    if (u8std == STD_TVI) {
        PRT_VISS_ERR("error, Set %s decoder, not support STD_TVI ", SNS_NAME);
        return s32Ret;
    }

    switch (u8Type) {
        case TYPE_720P25:
            CAMERA_Bt656DecoderCfg(dev, u8VinCH, TYPE_720P25);
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1280;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 720;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 25;
            if (u8VinCH == 0) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 1;
            } else if (u8VinCH == 1) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
            } else if (u8VinCH == 2) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 1;
            } else if (u8VinCH == 3) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 1;
            }
            u8Ch720pCount++;
            break;
        case TYPE_720P30:
            CAMERA_Bt656DecoderCfg(dev, u8VinCH, TYPE_720P30);
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1280;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 720;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 30;
            if (u8VinCH == 0) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 1;
            } else if (u8VinCH == 1) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
            } else if (u8VinCH == 2) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 1;
            } else if (u8VinCH == 3) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 1;
            }
            u8Ch720pCount++;
            break;
        case TYPE_1080P25:
            CAMERA_Bt656DecoderCfg(dev, u8VinCH, TYPE_1080P25);
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1920;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 1080;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 25;
            if (u8VinCH == 0) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
            } else if (u8VinCH == 1) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
            } else if (u8VinCH == 2) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0;
            } else if (u8VinCH == 3) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0;
            }
            u8Ch1080pCount++;
            break;
        case TYPE_1080P30:
            CAMERA_Bt656DecoderCfg(dev, u8VinCH, TYPE_1080P30);
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1920;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 1080;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 30;
            if (u8VinCH == 0) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
            } else if (u8VinCH == 1) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
            } else if (u8VinCH == 2) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0;
            } else if (u8VinCH == 3) {
                s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0;
            }
            u8Ch1080pCount++;
            break;
        default:
            PRT_VISS_ERR("Error, Not Support this Decoder type %d", u8Type);
            break;
    }

    if (u8Ch720pCount == 4) {
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0;
    }

    pstSnsState->enSnsInitMode = COMMON_MANUCFG;
    pstSnsState->as32SnsChFormat[u8VinCH] = u8Type;
    pstSnsState->as32SnsStd[u8VinCH] = u8std;
    u8ChFormat[u8VinCH] = u8Type;

    return s32Ret;
}

static EI_S32 CAMERA_Init(VISS_DEV dev)
{
    EI_U32 j, i;
    EI_S32 bank;
    const SNS_TYPE_ATTR_S *pstSnsType;
    SNS_STATE_S *pstSnsState = EI_NULL;
    EI_S32 s32Ret;
    EI_U8 tmp;
    EI_U8 tmp1;
    EI_U8 u8Tmp[2];
    EI_U8 u8VinCH = 0x00;
    EI_U8 u8VinCHFormat[4] = {0};
    CAMERA_S *pStCam = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);
    CAMERA_CHECK_POINTER(pstSnsState);

    pStCam = (CAMERA_S *)pstSnsState->pCam;
    pstSnsType = pstSnsState->pstSnsAttr;

    pthread_mutex_lock(&pStCam->mutex);

    if (pstSnsState->pstSnsAttr->enSnsType == TP9930_DVP_1920_1080_XXFPS_4CH_YUV) {

        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x04);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, 0x20);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3d, 0xe0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3d, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, 0x25);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x7a, 0x20);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3c, 0x20);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3c, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x7a, 0x25);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x44, 0x57);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x43, 0x12);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x45, 0x09);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf4, 0xa0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x44, 0x07);
        /* video setting */

        for (i = 0; i < VISS_DEV_MAX_CHN_NUM; i++) {
            s32Ret = pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, (0x00 + i));
            if (s32Ret != EI_SUCCESS) {
                PRT_VISS_ERR("%s pfnWriteReg err", SNS_NAME);
                pthread_mutex_unlock(&pStCam->mutex);
                return s32Ret;
            }
            pstSnsState->stI2cInfo.pfnReadReg(pstSnsState, 0x03, &tmp);

            switch (tmp & 0x07) {
                case TYPE_720P25:
                    CAMERA_SetChnFormat(dev, i, TYPE_720P25);
                    pstSnsState->pstSnsAttr->stChFormat[i].stSize.u32Width = 1280;
                    pstSnsState->pstSnsAttr->stChFormat[i].stSize.u32Height = 720;
                    pstSnsState->pstSnsAttr->stChFormat[i].u32FrameRate = 25;

                    if (i == 0) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 1;
                    } else if (i == 1) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
                    } else if (i == 2) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 1;
                    } else if (i == 3) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 1;
                    }

                    break;
                case TYPE_720P30:
                    CAMERA_SetChnFormat(dev, i, TYPE_720P30);
                    pstSnsState->pstSnsAttr->stChFormat[i].stSize.u32Width = 1280;
                    pstSnsState->pstSnsAttr->stChFormat[i].stSize.u32Height = 720;
                    pstSnsState->pstSnsAttr->stChFormat[i].u32FrameRate = 30;

                    if (i == 0) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 1;
                    } else if (i == 1) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
                    } else if (i == 2) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 1;
                    } else if (i == 3) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 1;
                    }

                    break;
                case TYPE_1080P25:
                    CAMERA_SetChnFormat(dev, i, TYPE_1080P25);
                    pstSnsState->pstSnsAttr->stChFormat[i].stSize.u32Width = 1920;
                    pstSnsState->pstSnsAttr->stChFormat[i].stSize.u32Height = 1080;
                    pstSnsState->pstSnsAttr->stChFormat[i].u32FrameRate = 25;

                    if (i == 0) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
                    } else if (i == 1) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
                    } else if (i == 2) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0;
                    } else if (i == 3) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0;
                    }

                    break;
                case TYPE_1080P30:
                    CAMERA_SetChnFormat(dev, i, TYPE_1080P30);
                    pstSnsState->pstSnsAttr->stChFormat[i].stSize.u32Width = 1920;
                    pstSnsState->pstSnsAttr->stChFormat[i].stSize.u32Height = 1080;
                    pstSnsState->pstSnsAttr->stChFormat[i].u32FrameRate = 30;

                    if (i == 0) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
                    } else if (i == 1) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
                    } else if (i == 2) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0;
                    } else if (i == 3) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0;
                    }

                    break;
                default:
                    CAMERA_SetChnFormat(dev, i, TYPE_1080P30);
                    pstSnsState->pstSnsAttr->stChFormat[i].stSize.u32Width = 1920;
                    pstSnsState->pstSnsAttr->stChFormat[i].stSize.u32Height = 1080;
                    pstSnsState->pstSnsAttr->stChFormat[i].u32FrameRate = 30;

                    if (i == 0) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
                    } else if (i == 1) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 0;
                    } else if (i == 2) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0;
                    } else if (i == 3) {
                        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 0;
                    }
                    break;
            }
        }

        goto OUT;

    }

    if (pstSnsState->pstSnsAttr->enSnsType == TP9930_DVP_ADAPTIVE_MASHUP_BT656_YUV) {
        CAMERA_Bt656DecoderStart(dev);
    }

    if (pstSnsState->pstSnsAttr->enSnsType == TP9930_DVP_1080P_720P_25FPS_2CH_BT656_YUV) {
        CAMERA_Bt656DecoderPllReset(dev);
        u8VinCHFormat[0] = TYPE_1080P25;
        u8VinCHFormat[1] = TYPE_720P25;
        u8VinCHFormat[2] = TYPE_1080P25;
        u8VinCHFormat[3] = TYPE_720P25;
        CAMERA_Bt656DecoderCfg(dev, 0, TYPE_1080P25);
        pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1920;
        pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 1080;
        pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
        CAMERA_Bt656DecoderCfg(dev, 1, TYPE_720P25);
        pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Width = 1280;
        pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Height = 720;
        pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 25;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
        CAMERA_Bt656DecoderCfg(dev, 2, TYPE_1080P25);
        pstSnsState->pstSnsAttr->stChFormat[2].stSize.u32Width = 1920;
        pstSnsState->pstSnsAttr->stChFormat[2].stSize.u32Height = 1080;
        pstSnsState->pstSnsAttr->stChFormat[2].u32FrameRate = 25;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0;
        CAMERA_Bt656DecoderCfg(dev, 3, TYPE_720P25);
        pstSnsState->pstSnsAttr->stChFormat[3].stSize.u32Width = 1280;
        pstSnsState->pstSnsAttr->stChFormat[3].stSize.u32Height = 720;
        pstSnsState->pstSnsAttr->stChFormat[3].u32FrameRate = 25;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 1;
        CAMERA_Bt656DecoderMuxCfg1(dev, u8VinCHFormat);
        goto OUT;
    }

    if (pstSnsState->pstSnsAttr->enSnsType == TP9930_DVP_1080P_720P_30FPS_2CH_BT656_YUV) {
        CAMERA_Bt656DecoderPllReset(dev);
        u8VinCHFormat[0] = TYPE_1080P30;
        u8VinCHFormat[1] = TYPE_720P30;
        u8VinCHFormat[2] = TYPE_1080P30;
        u8VinCHFormat[3] = TYPE_720P30;
        CAMERA_Bt656DecoderCfg(dev, 0, TYPE_1080P30);
        pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1920;
        pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 1080;
        pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 30;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh0 = 0;
        CAMERA_Bt656DecoderCfg(dev, 1, TYPE_720P30);
        pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Width = 1280;
        pstSnsState->pstSnsAttr->stChFormat[1].stSize.u32Height = 720;
        pstSnsState->pstSnsAttr->stChFormat[1].u32FrameRate = 30;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh1 = 1;
        CAMERA_Bt656DecoderCfg(dev, 2, TYPE_1080P30);
        pstSnsState->pstSnsAttr->stChFormat[2].stSize.u32Width = 1920;
        pstSnsState->pstSnsAttr->stChFormat[2].stSize.u32Height = 1080;
        pstSnsState->pstSnsAttr->stChFormat[2].u32FrameRate = 30;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh2 = 0;
        CAMERA_Bt656DecoderCfg(dev, 3, TYPE_720P30);
        pstSnsState->pstSnsAttr->stChFormat[3].stSize.u32Width = 1280;
        pstSnsState->pstSnsAttr->stChFormat[3].stSize.u32Height = 720;
        pstSnsState->pstSnsAttr->stChFormat[3].u32FrameRate = 30;
        s_astSnsAttr[0].stDevCfg.stVicCfg.stRecoveryMode.bCh3 = 1;
        CAMERA_Bt656DecoderMuxCfg1(dev, u8VinCHFormat);
        goto OUT;
    }

    if (pstSnsType->enSnsType == TP9930_DVP_1920_1080_25FPS_1CH_YUV) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        //output disable
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4d, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4e, 0x00);
        //PLL reset
        pstSnsState->stI2cInfo.pfnReadReg(pstSnsState, 0x44, &tmp);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x44, tmp | 0x40);
        pstSnsState->stI2cInfo.pfnReadReg(pstSnsState, 0xf4, &tmp1);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf4, tmp1 | 0x80);
        ei_msleep(10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x44, tmp);

        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x04);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, 0x20);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3d, 0xe0);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3d, 0x60);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3b, 0x25);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x40);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x7a, 0x20);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3c, 0x20);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x3c, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x7a, 0x25);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);

        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x44, 0x57);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x43, 0x12);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x45, 0x09);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf4, 0x80);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x44, 0x17);
    }

    if (pstSnsType->enSnsType == TP9930_DVP_TVI_1920_1080_50FPS_2CH_YUV) {
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4d, 0x00);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x4e, 0x00);

        pstSnsState->stI2cInfo.pfnReadReg(pstSnsState, 0x44, &u8Tmp[0]);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x44, (u8Tmp[0] | 0x40));

        pstSnsState->stI2cInfo.pfnReadReg(pstSnsState, 0xf4, &u8Tmp[1]);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0xf4, (u8Tmp[1] | 0x80));
        ei_msleep(10);
        pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x44, u8Tmp[0]);
    }

    if (pstSnsState->pstSnsAttr->enSnsType == TP9930_DVP_1920_1080_30FPS_2CH_BT656_YUV) {
        for (u8VinCH = 0; u8VinCH < 2; u8VinCH++) {
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1920;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 1080;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 30;
        }
    } else if (pstSnsState->pstSnsAttr->enSnsType == TP9930_DVP_1920_1080_25FPS_2CH_BT656_YUV) {
        for (u8VinCH = 0; u8VinCH < 2; u8VinCH++) {
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1920;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 1080;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 25;
        }
    } else if (pstSnsState->pstSnsAttr->enSnsType == TP9930_DVP_1280_720_30FPS_4CH_BT656_YUV) {
        for (u8VinCH = 0; u8VinCH < 4; u8VinCH++) {
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1280;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 720;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 30;
        }
    } else if (pstSnsState->pstSnsAttr->enSnsType == TP9930_DVP_1280_720_25FPS_4CH_BT656_YUV) {
        for (u8VinCH = 0; u8VinCH < 4; u8VinCH++) {
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1280;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 720;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 25;
        }
    }

    if (pstSnsState->pstSnsAttr->enSnsType == TP9930_DVP_1920_1080_25FPS_4CH_YUV) {
        for (u8VinCH = 0; u8VinCH < 4; u8VinCH++) {
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Width = 1920;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].stSize.u32Height = 1080;
            pstSnsState->pstSnsAttr->stChFormat[u8VinCH].u32FrameRate = 25;
        }
    }

    if (pstSnsState->pstSnsAttr->enSnsType == TP9930_DVP_1920_1080_25FPS_1CH_YUV) {
        pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Width = 1920;
        pstSnsState->pstSnsAttr->stChFormat[0].stSize.u32Height = 1080;
        pstSnsState->pstSnsAttr->stChFormat[0].u32FrameRate = 25;
    }

    for (j = 0; j < MAX_COF; j++) {
        s32Ret = pstSnsState->stI2cInfo.pfnwriteRegList(pstSnsState,
                pstSnsType->astRegCfgs[j].pstRegs, pstSnsType->astRegCfgs[j].u32RegsCnt);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s writeRegList err", SNS_NAME);
            pthread_mutex_unlock(&pStCam->mutex);
            return s32Ret;
        }
    }

OUT:
    pstSnsState->stI2cInfo.pfnReadReg(pstSnsState, 0x40, &bank);

    s32Ret = pstSnsState->stI2cInfo.pfnwriteRegList(pstSnsState,
            Audio_pcm_8k_16bit_8chns, ARRAY_SIZE(Audio_pcm_8k_16bit_8chns));
    if (s32Ret != EI_SUCCESS) {
        PRT_VISS_ERR("%s audio writeRegList err", SNS_NAME);
        pthread_mutex_unlock(&pStCam->mutex);
        return s32Ret;
    }

    pstSnsState->stI2cInfo.pfnWriteReg(pstSnsState, 0x40, bank);

    pthread_mutex_unlock(&pStCam->mutex);

    PRT_VISS_INFO("%s writeRegList success", SNS_NAME);

    return s32Ret;
}

static void CAMERA_Exit(VISS_DEV dev)
{
    EI_U8 u8i = 0;
    CAMERA_I2cExit(dev);

    u8Count = 0;
    u8Ch720pCount = 0;
    u8Ch1080pCount = 0;
    for (u8i = 0; u8i < 4; u8i++) {
        u8ChFormat[u8i] = 0xff;
    }

    return;
}

static EI_S32 CAMERA_SetImageMode(VISS_DEV dev, SNS_TYPE_E enSnsType)
{
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);
    CAMERA_CHECK_POINTER(pstSnsState);

    pstSnsState->enSnsType = enSnsType;
    pstSnsState->bSyncInit = EI_FALSE;

    return EI_SUCCESS;
}

static EI_S32 CAMERA_EnumSnstype(VISS_DEV VissDev, EI_U32 u32Index, SNS_TYPE_E *peSnstype)
{
    const SNS_TYPE_ATTR_S *pstSnsType;

    if (u32Index >= ARRAY_SIZE(s_astSnsAttr))
        return EN_ERR_NO_FOUND;

    pstSnsType = &s_astSnsAttr[u32Index];

    *peSnstype = pstSnsType->enSnsType;

    return EI_SUCCESS;
}

static EI_S32 CAMERA_GetStatus(VISS_DEV VissDev, SNS_STS_S *pstSts)
{
    const SNS_TYPE_ATTR_S *pstSnsType;
    SNS_STATE_S *pstSnsState = EI_NULL;
    EI_S32 s32Ret = EI_SUCCESS;
    EI_U32 i;
    I2C_INFO_S *pstI2cInfo = EI_NULL;
    EI_U8 tmp;
    CAMERA_S *pStCam = EI_NULL;

    SNS_GET_CTX(VissDev, pstSnsState);
    CAMERA_CHECK_POINTER(pstSnsState);

    pStCam = (CAMERA_S *)pstSnsState->pCam;
    pstI2cInfo = &pstSnsState->stI2cInfo;
    pstSnsType = pstSnsState->pstSnsAttr;

    pthread_mutex_lock(&pStCam->mutex);

#if 0
    for (i = 0; i <= 0xff; i++) {
        s32Ret = pstSnsState->stI2cInfo.pfnReadReg(pstSnsState, i, &u8Tmp);
        if (s32Ret != 0) {
            PRT_VISS_ERR("%s  addr 0x%x, val 0x%x\n", SNS_NAME, i, u8Tmp);
        }
        PRT_VISS_ERR("addr 0x%x, val 0x%x\n", i, u8Tmp);
    }
#endif

    for (i = 0; i < pstSnsType->enWorkMode; i++) {
        s32Ret += pstI2cInfo->pfnWriteReg(pstSnsState, 0x40, (0x00 + i));
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnWriteReg err", SNS_NAME);
            pthread_mutex_unlock(&pStCam->mutex);
            return s32Ret;
        }

        tmp = 0;
        s32Ret += pstI2cInfo->pfnReadReg(pstSnsState, 0x01, &tmp);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnReadReg err", SNS_NAME);
        }
#if 0
        tmp = (tmp & 0x80) >> 7;
        if (!tmp) {
            s32Ret += pstI2cInfo->pfnReadReg(pstSnsState, 0x2f, &tmp);
            if (s32Ret != EI_SUCCESS) {
                PRT_VISS_ERR("%s pfnReadReg err", SNS_NAME);
                return s32Ret;
            }

            if (0x80 == tmp) {
                s32Ret += pstI2cInfo->pfnReadReg(pstSnsState, 0x04, &tmp);
                if (s32Ret != EI_SUCCESS) {
                    PRT_VISS_ERR("%s pfnReadReg err", SNS_NAME);
                    return s32Ret;
                }

                if (tmp < 0x30)
                    tmp = 0;
                else
                    tmp = 1;
            }
        }
#endif
        if ((tmp & (0x1 << 5)) && (tmp & (0x1 << 6))) {
            tmp = 0;
        } else {
            tmp = 1;
        }
        pstSts->bChnSts[i] = tmp;
    }

    pthread_mutex_unlock(&pStCam->mutex);

    return s32Ret;
}

static EI_S32 CAMERA_GetImage(VISS_DEV VissDev, SNS_IMAGE_S *pstSts)
{
    const SNS_TYPE_ATTR_S *pstSnsType;
    SNS_STATE_S *pstSnsState = EI_NULL;
    EI_S32 s32Ret = EI_SUCCESS;
    EI_U32 i;
    I2C_INFO_S *pstI2cInfo = EI_NULL;
    EI_U8 tmp;
    CAMERA_S *pStCam = EI_NULL;

    SNS_GET_CTX(VissDev, pstSnsState);
    CAMERA_CHECK_POINTER(pstSnsState);

    pStCam = (CAMERA_S *)pstSnsState->pCam;
    pstI2cInfo = &pstSnsState->stI2cInfo;
    pstSnsType = pstSnsState->pstSnsAttr;

    pthread_mutex_lock(&pStCam->mutex);

    for (i = 0; i < pstSnsType->enWorkMode; i++) {
        s32Ret += pstI2cInfo->pfnWriteReg(pstSnsState, 0x40, (0x00 + i));
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnWriteReg err", SNS_NAME);
            pthread_mutex_unlock(&pStCam->mutex);
            return s32Ret;
        }

        /* Get Brightness */
        tmp = 0;
        s32Ret += pstI2cInfo->pfnReadReg(pstSnsState, BRIGHTNESS, &tmp);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnReadReg err", SNS_NAME);
        }
        pstSts->brightness[i] = tmp;
        /* Get Contrast */
        tmp = 0;
        s32Ret += pstI2cInfo->pfnReadReg(pstSnsState, CONTRAST, &tmp);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnReadReg err", SNS_NAME);
        }
        pstSts->contrast[i] = tmp;
        /* Get Saturation */
        tmp = 0;
        s32Ret += pstI2cInfo->pfnReadReg(pstSnsState, SATURATION, &tmp);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnReadReg err", SNS_NAME);
        }
        pstSts->saturation[i] = tmp;
        /* Get Hue */
        tmp = 0;
        s32Ret += pstI2cInfo->pfnReadReg(pstSnsState, HUE, &tmp);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnReadReg err", SNS_NAME);
        }
        pstSts->hue[i] = tmp;
        /* Get Sharpness */
        tmp = 0;
        s32Ret += pstI2cInfo->pfnReadReg(pstSnsState, SHARPNESS, &tmp);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnReadReg err", SNS_NAME);
        }
        pstSts->sharpness[i] = (tmp & 0x1F);

    }

    pthread_mutex_unlock(&pStCam->mutex);

    return s32Ret;
}

static EI_S32 CAMERA_SetImage(VISS_DEV VissDev, SNS_IMAGE_S *pstSts)
{
    const SNS_TYPE_ATTR_S *pstSnsType;
    SNS_STATE_S *pstSnsState = EI_NULL;
    EI_S32 s32Ret = EI_SUCCESS;
    EI_U32 i;
    I2C_INFO_S *pstI2cInfo = EI_NULL;
    EI_U8 tmp;
    CAMERA_S *pStCam = EI_NULL;

    SNS_GET_CTX(VissDev, pstSnsState);
    CAMERA_CHECK_POINTER(pstSnsState);

    pStCam = (CAMERA_S *)pstSnsState->pCam;
    pstI2cInfo = &pstSnsState->stI2cInfo;
    pstSnsType = pstSnsState->pstSnsAttr;

    pthread_mutex_lock(&pStCam->mutex);

    for (i = 0; i < pstSnsType->enWorkMode; i++) {
        s32Ret += pstI2cInfo->pfnWriteReg(pstSnsState, 0x40, (0x00 + i));
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnWriteReg err", SNS_NAME);
            pthread_mutex_unlock(&pStCam->mutex);
            return s32Ret;
        }

        /* Set Brightness */
        s32Ret += pstI2cInfo->pfnWriteReg(pstSnsState, BRIGHTNESS, pstSts->brightness[i]);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnWriteReg err", SNS_NAME);
        }
        /* Set Contrast */
        s32Ret += pstI2cInfo->pfnWriteReg(pstSnsState, CONTRAST, pstSts->contrast[i]);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnWriteReg err", SNS_NAME);
        }
        /* Set Saturation */
        s32Ret += pstI2cInfo->pfnWriteReg(pstSnsState, SATURATION, pstSts->saturation[i]);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnWriteReg err", SNS_NAME);
        }
        /* Set Hue */
        s32Ret += pstI2cInfo->pfnWriteReg(pstSnsState, HUE, pstSts->hue[i]);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnWriteReg err", SNS_NAME);
        }
        /* Set Sharpness */
        tmp = 0;
        s32Ret += pstI2cInfo->pfnReadReg(pstSnsState, SHARPNESS, &tmp);
        tmp &= 0xe0;
        tmp |= (pstSts->sharpness[i] & 0x1F);
        s32Ret += pstI2cInfo->pfnWriteReg(pstSnsState, SHARPNESS, tmp);
        if (s32Ret != EI_SUCCESS) {
            PRT_VISS_ERR("%s pfnWriteReg err", SNS_NAME);
        }
    }

    pthread_mutex_unlock(&pStCam->mutex);

    return s32Ret;
}


static EI_S32 CAMERA_InitSensorExpFunction(SENSOR_EXP_FUNC_S *pstSensorExpFunc)
{
    CAMERA_CHECK_POINTER(pstSensorExpFunc);

    memset(pstSensorExpFunc, 0, sizeof(SENSOR_EXP_FUNC_S));

    pstSensorExpFunc->pfnSensorPowerUp         = CAMERA_PowerUp;
    pstSensorExpFunc->pfnSensorPowerDown       = CAMERA_PowerDown;
    pstSensorExpFunc->pfnSensorDetect          = CAMERA_Detect;
    pstSensorExpFunc->pfnSensorInit            = CAMERA_Init;
    pstSensorExpFunc->pfnSensorStream          = CAMERA_Stream;
    pstSensorExpFunc->pfnSensorExit            = CAMERA_Exit;
    pstSensorExpFunc->pfnSensorSetImageMode    = CAMERA_SetImageMode;
    pstSensorExpFunc->pfnSensorEnumSnstype     = CAMERA_EnumSnstype;
    pstSensorExpFunc->pfnSensorGetStatus       = CAMERA_GetStatus;
    pstSensorExpFunc->pfnSensorSetImage        = CAMERA_SetImage;
    pstSensorExpFunc->pfnSensorGetImage        = CAMERA_GetImage;
    pstSensorExpFunc->pfnSensorDecoderInit     = CAMERA_DecoderInit;
    pstSensorExpFunc->pfnSensorSetDecoder      = CAMERA_SetDecoder;
    pstSensorExpFunc->pfnSensorSetAudioVolume  = CAMERA_SetAudioVolume;
    pstSensorExpFunc->pfnSensorI2cWrite       = CAMERA_I2cWrite;
    pstSensorExpFunc->pfnSensorI2cRead        = CAMERA_I2cRead;

    return EI_SUCCESS;
}


/****************************************************************************
 * callback structure                                                       *
 ****************************************************************************/

static EI_S32 CAMERA_CtxInit(VISS_DEV dev)
{
    SNS_STATE_S *pastSnsStateCtx = EI_NULL;
    CAMERA_S *pStCam = EI_NULL;

    SNS_GET_CTX(dev, pastSnsStateCtx);
    CAMERA_CHECK_POINTER(pastSnsStateCtx);

    memset(pastSnsStateCtx, 0, sizeof(SNS_STATE_S));

    pastSnsStateCtx->pCam = malloc(sizeof(CAMERA_S));
    pStCam = (CAMERA_S *)pastSnsStateCtx->pCam;
    pthread_mutex_init(&pStCam->mutex, NULL);

    pastSnsStateCtx->pstPowerUpAct      = s_stPowerUpAct;
    pastSnsStateCtx->pstPowerDownAct    = s_sPowerDownAct;
    pastSnsStateCtx->u8PwrUpActs        = ARRAY_SIZE(s_stPowerUpAct);
    pastSnsStateCtx->u8PwrDnActs        = ARRAY_SIZE(s_sPowerDownAct);

    return EI_SUCCESS;
}

static EI_S32 CAMERA_CtxExit(VISS_DEV dev)
{
    SNS_STATE_S *pastSnsStateCtx = EI_NULL;
    CAMERA_S *pStCam = EI_NULL;

    SNS_GET_CTX(dev, pastSnsStateCtx);
    CAMERA_CHECK_POINTER(pastSnsStateCtx);

    pStCam = (CAMERA_S *)pastSnsStateCtx->pCam;
    pthread_mutex_destroy(&pStCam->mutex);

    if (pStCam) {
        free(pStCam);
        pStCam = EI_NULL;
    }

    return EI_SUCCESS;
}

static EI_S32 CAMERA_RegisterVissCallback(VISS_DEV dev, SNS_TYPE_E enType)
{
    EI_S32 s32Ret;
    SENSOR_S stSns = {0};
    EI_U32 i;
    SNS_STATE_S *pstSnsState = EI_NULL;

    s32Ret = CAMERA_CtxInit(dev);
    if (EI_SUCCESS != s32Ret) {
        return EI_FAILURE;
    }

    SNS_GET_CTX(dev, pstSnsState);

    for (i = 0; i < ARRAY_SIZE(s_astSnsAttr); i++) {
        if (enType == s_astSnsAttr[i].enSnsType) {
            pstSnsState->pstSnsAttr = &s_astSnsAttr[i];
            break;
        }
    }

    pstSnsState->enSnsType = enType;
    pstSnsState->Dev = dev;

    if (i >= ARRAY_SIZE(s_astSnsAttr)) {
        PRT_VISS_ERR("%s does not support this chn configuration", SNS_NAME);
        return EI_FAILURE;
    }

    s32Ret = CAMERA_I2cInit(dev);
    if (EI_SUCCESS != s32Ret) {
        return EI_FAILURE;
    }

    stSns.stSnsAttrInfo.eSensorId = SNS_ID;
    stSns.stSnsAttrInfo.enDevType = DEV_TYPE;
    stSns.stSnsAttrInfo.pstSns = pstSnsState;

    s32Ret  = CAMERA_InitSensorExpFunction(&stSns.stSnsAttrInfo.stSnsExp);
    s32Ret |= VISS_SensorRegCallBack(dev, &stSns);
    if (EI_SUCCESS != s32Ret) {
        PRT_VISS_ERR("%s sensor register callback function failed!\n", SNS_NAME);
        return s32Ret;
    }

    s32Ret = CAMERA_OpenI2c(pstSnsState);
    CAMERA_CHECK_SUCCESS(s32Ret);

    return EI_SUCCESS;
}

static EI_S32 CAMERA_UnregisterVissCallback(VISS_DEV dev)
{
    EI_S32 s32Ret;
    SNS_STATE_S *pstSnsState = EI_NULL;

    SNS_GET_CTX(dev, pstSnsState);

    s32Ret = CAMERA_ExitI2c(pstSnsState);
    CAMERA_CHECK_SUCCESS(s32Ret);

    s32Ret = VISS_SensorUnRegCallBack(dev, SNS_ID);
    if (EI_SUCCESS != s32Ret) {
        PRT_VISS_ERR("%s sensor unregister callback function failed!\n", SNS_NAME);
        return s32Ret;
    }

    CAMERA_CtxExit(dev);

    return EI_SUCCESS;
}

static EI_S32 CAMERA_GetVissDevAttrBySns(SNS_TYPE_E enType,
    VISS_DEV_ATTR_S *pstVissDevAttr)
{
    EI_U32 i;
    const SNS_TYPE_ATTR_S *pstSnsType;

    for (i = 0; i < ARRAY_SIZE(s_astSnsAttr); i++) {
        if (enType == s_astSnsAttr[i].enSnsType) {
            pstSnsType = &s_astSnsAttr[i];
            pstVissDevAttr->stSize          = pstSnsType->stSize;
            pstVissDevAttr->enWorkMode      = pstSnsType->enWorkMode;
            pstVissDevAttr->mClock          = pstSnsType->u32Mclock;
            pstVissDevAttr->enPixelFormat   = pstSnsType->enPixelFormat;
            pstVissDevAttr->enWdrMode       = pstSnsType->enWdrMode;
            pstVissDevAttr->enIspWdrMode    = pstSnsType->enIspWdrMode;
            pstVissDevAttr->enRgbSeq        = pstSnsType->enRgbSeq;
            pstVissDevAttr->u32ModuleClk    = pstSnsType->u32ModuleClk;
            pstVissDevAttr->u32Fps          = pstSnsType->u32FrameRate;
            pstVissDevAttr->u32IspClk       = pstSnsType->u32IspClk;
            pstVissDevAttr->u32IppuClk      = pstSnsType->u32IppuClk;
            pstVissDevAttr->pcSnsName       = SNS_NAME;
            pstVissDevAttr->stDevCfg        = pstSnsType->stDevCfg;
            return EI_SUCCESS;
        }
    }

    PRT_VISS_ERR("%s does not support this dev configuration", SNS_NAME);

    return EI_FAILURE;
}

static EI_S32 CAMERA_GetVissChnAttrBySns(SNS_TYPE_E enType,
    VISS_CHN_ATTR_S *pstVissChnAttr)
{
    EI_U32 i;
    const SNS_TYPE_ATTR_S *pstSnsType;

    for (i = 0; i < ARRAY_SIZE(s_astSnsAttr); i++) {
        if (enType == s_astSnsAttr[i].enSnsType) {
            pstSnsType = &s_astSnsAttr[i];
            pstVissChnAttr->stSize           = pstSnsType->stSize;
            pstVissChnAttr->enPixelFormat    = pstSnsType->enPixelFormat;
            pstVissChnAttr->stFrameRate.s32SrcFrameRate      = pstSnsType->u32FrameRate;
            return EI_SUCCESS;
        }
    }

    PRT_VISS_ERR("%s does not support this chn configuration", SNS_NAME);

    return EI_FAILURE;

}

CAMERA_OBJ_S stCameraTp9930dvpObj = {
    .pfnRegisterVissCallback    = CAMERA_RegisterVissCallback,
    .pfnUnRegisterVissCallback  = CAMERA_UnregisterVissCallback,
    .pfnRegisterIspCallback     = EI_NULL,
    .pfnUnRegisterIspCallback   = EI_NULL,
    .pfnGetVissDevAttrBySns     = CAMERA_GetVissDevAttrBySns,
    .pfnGetVissChnAttrBySns     = CAMERA_GetVissChnAttrBySns,
};

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */

